Blog

How To Test WooCommerce Webhooks

Webhooks is a term used for sending data to a URL when an event happens. An example is when someone subscribes to an email marketing list, the service that manages the list can send data like the subscriber’s name and email to another system like a Customer Relationship Manager. WooCommerce Webhooks were added to the WooCommerce 2.2 codebase in July of 2014.

Note: This how to is tested with WooCommerce 3.0.8 and WordPress 4.8.

Setting up WooCommerce Webhooks

To get started with webhooks, you’ll want to log in to your WooCommerce shop as an administrator. Navigate to WooCommerce > Settings and click the API tab. Click the Webhooks link in the sub menu. At first you’ll see an empty list of webhooks.

This is the empty woocommerce webhooks settings page.

The first step is to press Add Webhook. The webhook will be added and then the settings fields will be displayed. The settings fields are described below.

Name

This is a description only for store administrators. This can be set to whatever will help you know what the webhook is for.

Status

Webhook status of either Active, Paused, or Disabled.

Topic

The event that will cause the webhook to fire. WooCommerce supplies 12 actions and two custom actions. The pre-defined actions are listed below.

  1. Coupon created
  2. Coupon updated
  3. Coupon deleted
  4. Customer created
  5. Customer updated
  6. Customer deleted
  7. Order created
  8. Order updated
  9. Order deleted
  10. Product created
  11. Product updated
  12. Product deleted

The two custom actions are Action and Custom.

Action

If Action is set as the Topic, then an additional setting field named Action Event is displayed. This field will contain the WordPress hook that will fire the webhook. For example, if the site has a custom plugin with this line:

do_action( 'after_order_exported' );

Setting the Action event setting to ‘after_order_exported’ will fire the hook at the appropriate time.

Custom

If Custom is set as the Topic, then an additional setting field named Custom topic is displayed. This field will contain the name of a custom topic that has been added using this filter:

woocommerce_webhook_topic_hooks

Delivery URL

This is the URL that the webhook payload will be sent to.

Secret

The secret field is used to generate a hash of the webhook’s body and that hash is provided in the request headers. This can be used to authenticate the webhook on the receiving side.

API Version

Choose one of three available API versions. It’s okay to leave this as “WP REST API Integration v2” unless you have special circumstances.

For testing purposes, I set up my webhook with these options:

  • Name: Product Created
  • Status: Active
  • Topic: Product created
  • Delivery URL: Leave this empty for now
  • Secret: a random string
  • API Version: WP REST API Integration v2

The webhook can’t be saved yet, so leave this page and open a new browser window.

Test WooCommerce Webhooks

To test the WooCommerce Webhook, I’m going to use RequestBin.

RequestBin is a free site that lets you quickly accept HTTP requests like webhooks.

Go to https://requestb.in/ and press Create a RequestBin. Optionally check the “Private” checkbox. Next, I’m taken to a page with a bunch of data. Most important is the Bin URL at the top of the page.

After you've created a requestbin copy the Bin URL back to your WooCommerce site.

Copy the Bin URL to the webhook settings page in the Delivery URL field and press Save Webhook. Keep the requestb.in page open as we’ll need this after the test.

The webhook with Delivery URL added.

The next step is to do the action that will trigger the webhook. For this example, I’m going to create a product. To do this I navigate to Products > Add Product. I add a test product named Fuzzy Slippers, add some content, and set a price of $50. When I press Publish the product will be created and the webhook will be triggered.

To trigger this webhook I'll add a WooCommerce product.

After publishing the product, go back to the RequestBin window and press the Inspect button in the top right corner of the page.

To see what has been delivered to the request bin press the blue circle next to the bin url.

You should see the connection from WooCommerce when the product was added at the top of the page. Here is the new product webhook data. The webhook headers are displayed, and the raw body which includes all of the product information in JSON format is shown.

Inspecting the bin will show all the data sent to it by WooCommerce

You can also scroll down and see connections from when the Delivery URL was added and the webhook saved. WooCommerce will ping the URL to make sure it can be reached.

Using RequestBin is a fast, free, and easy way to test WooCommerce webhooks, to make sure they are working and be able to inspect the payload and see what is being delivered.

Get our best WooCommerce advice!

Delivered directly to your inbox

Your email is 100% private. I hate spam too. Powered by ConvertKit

Daniel Espinoza

Daniel has been building ecommerce plugins and sites since 2007. He built the first commercial plugin for WooCommerce in 2011 and has built dozens of plugins and sites since.

Follow Daniel on Twitter