PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, February 7, 2022

[FIXED] Prevent WooCommerce from firing product update webhook on REST API update only

 February 07, 2022     hook-woocommerce, woocommerce, woocommerce-rest-api, wordpress     No comments   

Issue

I am trying to create a stock sync system that communicates with WooCommerce via REST API and webhooks. It works simply like that:

  1. If the product was updated - the webhook is fired to my API which creates the event with the current stock information.
  2. When event is created it is being processed and the product update information is sent via REST to other WooCommerce stores in my "network". The product is updated.

The issue here is that it creates some kind of infinite loop as when the product is updated on other website it fires webhook again and creates a new event in my API again.

Question: Is it possible to prevent WooCommerce from firing product update webhooks ONLY when product is updated via REST API (or specific function)?


Solution

Yes, there is an example using the filter woocommerce_webhook_should_deliver here: https://shanerutter.co.uk/fix-woocommerce-webhook-loop/

Also, I've had luck un-scheduling the Action Scheduler actions upon their creation, which is a consequence of a REST API inventory type sync job firing product updated hooks and web hooks:

add_action( 'init', function() {
    as_unschedule_all_actions( 'adjust_download_permissions' );
} );


Answered By - Sean Conklin
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing