From 9b590dfa75b79f59e8aeca31b5fc2bcd00e9c29a Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Fri, 27 May 2016 11:35:16 +0100 Subject: [PATCH] Prevent both creation and update webhooks firing on product save. Closes #10970 cc @claudiosmweb --- includes/class-wc-webhook.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/includes/class-wc-webhook.php b/includes/class-wc-webhook.php index 573f8b3a277..7365cf5f6f0 100644 --- a/includes/class-wc-webhook.php +++ b/includes/class-wc-webhook.php @@ -155,9 +155,10 @@ class WC_Webhook { } elseif ( 'order' == $this->get_resource() && ! in_array( get_post_type( absint( $arg ) ), wc_get_order_types( 'order-webhooks' ) ) ) { $should_deliver = false; - } elseif ( 0 === strpos( $current_action, 'woocommerce_process_shop' ) ) { - // the `woocommerce_process_shop_*` hook fires for both updates - // and creation so check the post creation date to determine the actual event + } elseif ( 0 === strpos( $current_action, 'woocommerce_process_shop' ) || 0 === strpos( $current_action, 'woocommerce_process_product' ) ) { + // the `woocommerce_process_shop_*` and `woocommerce_process_product_*` hooks + // fire for create and update of products and orders, so check the post + // creation date to determine the actual event $resource = get_post( absint( $arg ) ); // a resource is considered created when the hook is executed within 10 seconds of the post creation date