WooCommerce has a webhook feature that allows you to send product data to a webhook url when a certain product status is made. The configuration of the webhooks is at WooCommerce>Settings>Advanced>Webhooks
The product states to choose from to fire the webhook are referred to as Topics and include states like Order Created, Order Updated and Order Deleted.
Webhook Topics
Firing Webhook with custom WooCommerce Action
Also in the above list is an option for an Action which allows for an Action Event (hook) to be added which allows you to fire the webhook when a WooCommerce hook is fired.
Action woocommerce_order_status_processing
So in the above an action is selected as a Topic then a WooCommerce hook is added – in the example it is :
woocommerce_order_status_processing
Here I want to send the order details only when the order has a state of processing, you can choose from a wide range of hooks, depending when you want to send the data.
The webhook will fire when the action is fired, but one of the main drawbacks of using a WooCommerce custom action is that only a small part of the product data is sent to the webhook url
So in the Raw Content section only the action name and order number are returned.
Function to send all product details
To get around this limitation there is a function that can be added via the themes functions.php file or as a plugin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Using this function and changing the webhook ID and data source will now return the full data to the webhook.
Where to find webhook ID
Now the full order details are sent.
Full order data returned in raw content
I am not the author of this code the source is stated in the code gist, however I have used and verify it works, the webhook testing I used is done at https://webhook.site
1 comment
ravi
bumped onto this page after 2 days of relentless search .. Thanks a ton! this is what i was looking for, works like a charm