Webhooks are automated actions that are triggered when a configured process occurs on your WordPress site. For instance, you may decide to send data from your website to another endpoint or service when an action occurs, such as a new booking product is placed or a new booking is created.
The Booking & Appointment Plugin for WooCommerce has nine configurable actions that can be triggered using webhooks.
- Booking Product created: Triggers an action when a Booking Product has been created on the website
- Booking Product updated: Triggers an action when a Booking Product has been deleted on the website
- Booking Product deleted: Triggers an action when a Booking Product has been deleted on the website
- Bookable Resource created: Triggers an action when a Bookable Resource has been created on the website
- Bookable Resource Updated: Triggers an action when a Bookable Resource has been updated
- Bookable Resource deleted: Triggers an action when a Bookable Resource has been deleted
- Booking created: Triggers an action when a new booking has been created manually by the Administrator or created via checkout by Customer
- Booking updated: Triggers an action when Booking information has been updated
- Booking deleted: Triggers an action when Booking has been deleted
Creating a Webhook
For this tutorial, we will be looking at how to pass information from a WordPress site to Request Bin. This information will be passed using webhooks and will be triggered when a Booking Product has been created.
RequestBin is a website where webhook events can be inspected for testing purposes.
To create a new webhook, go to Woocommerce > Settings > Advanced > Webhooks.
Click on Create a new webhook or Add webhook to display the Webhook data page as shown in the image below.
Create Webhook Page
On the Webhook data page, you will need to enter the following information:
- Name: The name to identify the Webhook action. It can be auto-generated (by WordPress) or changed to something. We’ll be using Booking Product Create Webhook here.
- Status: This defines the status of the Webhook after it has been created. It could be Active, Paused, or Disabled.
- Topic: This indicates the action that can trigger the Webhook. Here, you can configure any of the nine webhooks actions available in the plugin. In this tutorial, we will be using the Booking Product Created action.
- Delivery URL: This is the destination URL where you want data from your WordPress site to be sent to. Since we’re using the RequestBin site in this tutorial, head over to https://requestbin.com/ and set up an account to generate a URL. Enter the provided URL from RequestBin in the Delivery URL field in the webhook data page.
- Secret: According to WooCommerce, the Secret Key generates a hash of the delivered webhook and is provided in the request headers. Leave this field blank to use the default setting or provide a custom secret key.
- API version: The API version allows you to choose the API format in which WordPress shall use to send the data. Using the default option is perfectly fine, but if you’re creating a webhook for some third-party integration that only supports the legacy v3 version of the API, then you can set the data to that format.
Click the Save webhook button. You should see a Webhook update successfully notice, similar to the figure below.
Webhook created successfully Page
You can now create a Booking Product and confirm that the webhook has been triggered and data has been sent. We can confirm this by checking the RequestBin page to inspect the webhook event and the WooCommerce webhook log which can be found here: WooCommerce > Status > Logs.
RequestBin page showing webhook data received from WordPress site
WooCommerce log showing webhook data sent to RequestBin Delivery URL
The steps listed in this tutorial can be carried out for any of the other webhooks in the Booking & Appointment Plugin for WooCommerce.
The following WordPress plugins/tools may come in handy while troubleshooting or inspecting webhooks: