Trigger variable product sync hook after save
Because only a product ID is passed to callbacks on 'woocommerce_variable_product_sync', they will need to instantiate their own instance of the product to do anything useful with it. This creates a lot of potential for problems given that the product has at that stage had its data sync'd but not all of it saved. For example, a callback may modify some meta data on its own instance of the product, then save that, only to immediately have that overridden if the instance of $product in WC_Product_Variable::sync() also had changes to that meta data. Instead, trigger 'woocommerce_variable_product_sync' only after the product has been saved. This is backward compatible because the hook was triggered at the very end of the process in WC < 2.7.
This commit is contained in:
parent
497b4d986c
commit
7e61cb8a24
|
@ -455,11 +455,11 @@ class WC_Product_Variable extends WC_Product {
|
|||
$data_store->sync_stock_status( $product );
|
||||
self::sync_attributes( $product ); // Legacy update of attributes.
|
||||
|
||||
do_action( 'woocommerce_variable_product_sync', $product->get_id(), $product->get_visible_children( 'edit' ), $save );
|
||||
|
||||
if ( $save ) {
|
||||
$product->save();
|
||||
}
|
||||
|
||||
do_action( 'woocommerce_variable_product_sync', $product->get_id(), $product->get_visible_children( 'edit' ), $save );
|
||||
}
|
||||
return $product;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue