WooCommerce delayed webhooks using actions scheduler

Recently been contacted by a user who needed the ability to delay the WooCommerce webhooks by x time, this would allow other processes happening on the site to finish instead of firing the webhook straight away, for example waiting for the payment process to finalise. Delaying webhooks is not common practice, however some time special case arises!

Take a look at actions scheduler if you wish to read more into the scheduler system used by WooCommerce.

Code

The following code allows you to delay several WooCommerces webhooks by a set duration (seconds) and also run in two modes.

  1. Single Webhook, creates 1 single webhook but delayed by x seconds.
  2. Multi Webhook, creates 2 webhooks, the normal webhook created by WooCommerce and a second repeat webhook which runs x seconds later.

This code is provided as it and may require changes to work for your needs.

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

2 Comments

  1. Works like a charm!
    Thank you so much, you helped to resolve the problem i was struggling for 3 years now 😀