WC_Product_Data_Store_CPT::handle_updated_props() protected WC 3.0.0
Handle updated meta props after updating meta data.
{} Это метод класса: WC_Product_Data_Store_CPT{}
Хуки из метода
Возвращает
Null. Ничего.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->handle_updated_props( $product );
- $product(WC_Product) (обязательный) (передается по ссылке — &)
- Product Object.
Список изменений
С версии 3.0.0 | Введена. |
Код WC_Product_Data_Store_CPT::handle_updated_props() WC Product Data Store CPT::handle updated props WC 4.9.2
protected function handle_updated_props( &$product ) {
$price_is_synced = $product->is_type( array( 'variable', 'grouped' ) );
if ( ! $price_is_synced ) {
if ( in_array( 'regular_price', $this->updated_props, true ) || in_array( 'sale_price', $this->updated_props, true ) ) {
if ( $product->get_sale_price( 'edit' ) >= $product->get_regular_price( 'edit' ) ) {
update_post_meta( $product->get_id(), '_sale_price', '' );
$product->set_sale_price( '' );
}
}
if ( in_array( 'date_on_sale_from', $this->updated_props, true ) || in_array( 'date_on_sale_to', $this->updated_props, true ) || in_array( 'regular_price', $this->updated_props, true ) || in_array( 'sale_price', $this->updated_props, true ) || in_array( 'product_type', $this->updated_props, true ) ) {
if ( $product->is_on_sale( 'edit' ) ) {
update_post_meta( $product->get_id(), '_price', $product->get_sale_price( 'edit' ) );
$product->set_price( $product->get_sale_price( 'edit' ) );
} else {
update_post_meta( $product->get_id(), '_price', $product->get_regular_price( 'edit' ) );
$product->set_price( $product->get_regular_price( 'edit' ) );
}
}
}
if ( in_array( 'stock_quantity', $this->updated_props, true ) ) {
if ( $product->is_type( 'variation' ) ) {
do_action( 'woocommerce_variation_set_stock', $product );
} else {
do_action( 'woocommerce_product_set_stock', $product );
}
}
if ( in_array( 'stock_status', $this->updated_props, true ) ) {
if ( $product->is_type( 'variation' ) ) {
do_action( 'woocommerce_variation_set_stock_status', $product->get_id(), $product->get_stock_status(), $product );
} else {
do_action( 'woocommerce_product_set_stock_status', $product->get_id(), $product->get_stock_status(), $product );
}
}
if ( array_intersect( $this->updated_props, array( 'sku', 'regular_price', 'sale_price', 'date_on_sale_from', 'date_on_sale_to', 'total_sales', 'average_rating', 'stock_quantity', 'stock_status', 'manage_stock', 'downloadable', 'virtual', 'tax_status', 'tax_class' ) ) ) {
$this->update_lookup_table( $product->get_id(), 'wc_product_meta_lookup' );
}
// Trigger action so 3rd parties can deal with updated props.
do_action( 'woocommerce_product_object_updated_props', $product, $this->updated_props );
// After handling, we can reset the props array.
$this->updated_props = array();
}