From 98b0fcbdff5cbe3913cb63aac44e74599d95d11a Mon Sep 17 00:00:00 2001 From: pjv Date: Tue, 13 Oct 2020 13:36:42 -0500 Subject: [PATCH] =?UTF-8?q?add=20=E2=80=9Cbefore=E2=80=9D=20stock=20change?= =?UTF-8?q?=20action=20hooks=20to=20CRUD=20transaction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/data-stores/class-wc-product-data-store-cpt.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/includes/data-stores/class-wc-product-data-store-cpt.php b/includes/data-stores/class-wc-product-data-store-cpt.php index 6158a4cad86..91f1156e7c8 100644 --- a/includes/data-stores/class-wc-product-data-store-cpt.php +++ b/includes/data-stores/class-wc-product-data-store-cpt.php @@ -568,6 +568,14 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da case 'date_on_sale_to': $value = $value ? $value->getTimestamp() : ''; break; + case 'stock_quantity': + // Fire actions to let 3rd parties know the stock is about to be changed. + if ( $product->is_type('variation' ) ) { + do_action( 'woocommerce_variation_before_set_stock', $product ); + } else { + do_action( 'woocommerce_product_before_set_stock', $product ); + } + break; } $updated = $this->update_or_delete_post_meta( $product, $meta_key, $value );