Add before set stock action
Add product and variation `before_set_stock` actions to allow 3rd party plugins to snapshot a product’s stock quantity before it is updated.
This commit is contained in:
parent
86f8788525
commit
ff9a3f2e1e
|
@ -38,6 +38,13 @@ function wc_update_product_stock( $product, $stock_quantity = null, $operation =
|
|||
$product_with_stock = $product_id_with_stock !== $product->get_id() ? wc_get_product( $product_id_with_stock ) : $product;
|
||||
$data_store = WC_Data_Store::load( 'product' );
|
||||
|
||||
// Fire actions to let 3rd parties know the stock is about to be changed.
|
||||
if ($product_with_stock->is_type('variation')) {
|
||||
do_action('woocommerce_variation_before_set_stock', $product_with_stock);
|
||||
} else {
|
||||
do_action('woocommerce_product_before_set_stock', $product_with_stock);
|
||||
}
|
||||
|
||||
// Update the database.
|
||||
$new_stock = $data_store->update_product_stock( $product_id_with_stock, $stock_quantity, $operation );
|
||||
|
||||
|
|
Loading…
Reference in New Issue