Source
x
if ( ! empty( $meta_value ) && is_float( $meta_value ) && ! registered_meta_key_exists( 'post', $meta_key ) && in_array( get_post_type( $object_id ), array_merge( wc_get_order_types(), array( 'shop_coupon', 'product', 'product_variation' ) ), true ) ) {
<?php
/**
* Post Data
*
* Standardises certain post data on save.
*
* @package WooCommerce\Classes\Data
* @version 2.2.0
*/
defined( 'ABSPATH' ) || exit;
/**
* Post data class.
*/
class WC_Post_Data {
/**
* Editing term.
*
* @var object
*/
private static $editing_term = null;
/**
* Hook in methods.
*/
public static function init() {
add_filter( 'post_type_link', array( __CLASS__, 'variation_post_link' ), 10, 2 );
add_action( 'shutdown', array( __CLASS__, 'do_deferred_product_sync' ), 10 );
add_action( 'set_object_terms', array( __CLASS__, 'force_default_term' ), 10, 5 );
add_action( 'set_object_terms', array( __CLASS__, 'delete_product_query_transients' ) );
add_action( 'deleted_term_relationships', array( __CLASS__, 'delete_product_query_transients' ) );
add_action( 'woocommerce_product_set_stock_status', array( __CLASS__, 'delete_product_query_transients' ) );
add_action( 'woocommerce_product_set_visibility', array( __CLASS__, 'delete_product_query_transients' ) );
add_action( 'woocommerce_product_type_changed', array( __CLASS__, 'product_type_changed' ), 10, 3 );
add_action( 'edit_term', array( __CLASS__, 'edit_term' ), 10, 3 );
add_action( 'edited_term', array( __CLASS__, 'edited_term' ), 10, 3 );
add_filter( 'update_order_item_metadata', array( __CLASS__, 'update_order_item_metadata' ), 10, 5 );
add_filter( 'update_post_metadata', array( __CLASS__, 'update_post_metadata' ), 10, 5 );
add_filter( 'wp_insert_post_data', array( __CLASS__, 'wp_insert_post_data' ) );
add_filter( 'oembed_response_data', array( __CLASS__, 'filter_oembed_response_data' ), 10, 2 );
// Status transitions.
add_action( 'transition_post_status', array( __CLASS__, 'transition_post_status' ), 10, 3 );
add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
add_action( 'wp_trash_post', array( __CLASS__, 'trash_post' ) );
add_action( 'untrashed_post', array( __CLASS__, 'untrash_post' ) );
add_action( 'before_delete_post', array( __CLASS__, 'before_delete_order' ) );
// Meta cache flushing.
add_action( 'updated_post_meta', array( __CLASS__, 'flush_object_meta_cache' ), 10, 4 );
add_action( 'updated_order_item_meta', array( __CLASS__, 'flush_object_meta_cache' ), 10, 4 );
}
/**
* Link to parent products when getting permalink for variation.
*
* @param string $permalink Permalink.
* @param WP_Post $post Post data.
*
* @return string
*/
public static function variation_post_link( $permalink, $post ) {
if ( isset( $post->ID, $post->post_type ) && 'product_variation' === $post->post_type ) {
$variation = wc_get_product( $post->ID );
if ( $variation && $variation->get_parent_id() ) {
return $variation->get_permalink();
}
}
return $permalink;
}
/**
* Sync products queued to sync.
*/
public static function do_deferred_product_sync() {
global $wc_deferred_product_sync;
if ( ! empty( $wc_deferred_product_sync ) ) {
$wc_deferred_product_sync = wp_parse_id_list( $wc_deferred_product_sync );
array_walk( $wc_deferred_product_sync, array( __CLASS__, 'deferred_product_sync' ) );
}
}
/**
* Sync a product.
*
* @param int $product_id Product ID.
*/