# Start a workflow from WooCommerce events

> Run a workflow when WooCommerce reports a new or changed order, product, customer, or coupon, with a Webhook block set to WooCommerce.

To run a workflow when WooCommerce reports a new or changed order, product, customer, or coupon, add a **Webhook** block whose **Source** is **WooCommerce** and give its URL to a webhook in your store's settings. WooCommerce posts one event per request. Each event starts its own run.

You need access to the WooCommerce settings of the store, and edit access to the workflow's project. The WooCommerce steps happen in the store's own admin pages.

## Add the Webhook block and generate its URL

1. In a draft workflow, add a **Webhook** block. The block palette also lists **WooCommerce webhook** in the **Start** group, which adds the block with its source already set.
2. Under **Source**, choose **WooCommerce**. The line under the setting reads "Verifies the signature · one run per event".
3. Under **Webhook URL**, select **Generate URL**, then copy the URL.

The badge beside the URL reads "Runs start after publish". The URL contains a token, and anyone who has the URL can send requests to it. Keep it out of shared documents.

## Create the webhook in WooCommerce

WooCommerce does not issue a secret for you to copy. You choose one, enter it in the webhook's form, and save the same value in OutWin. Make it long and random, use only letters and digits, and keep a copy until the next section. WordPress can store other characters differently from how you typed them, and the signature then does not match.

1. In the store's admin, open **WooCommerce**, then **Settings**, **Advanced**, and **Webhooks**, and select **Add webhook**.
2. Enter a **Name**, and set **Status** to **Active**.
3. Under **Topic**, choose what the webhook reports, such as an order being created.
4. Paste the URL you copied into **Delivery URL**.
5. Enter the secret you chose in **Secret**.
6. Select **Save webhook**.

A WooCommerce webhook sends one topic. To receive several topics on one block, add a webhook for each, with the same **Delivery URL** and the same **Secret**.

The first time a webhook is saved as **Active**, WooCommerce sends the URL a short request to check that it answers. The block answers it, also while the workflow is a draft. **Recent deliveries** lists it as **Handshake** with "WooCommerce checked that the URL answers.", and the last line under **Set up** reads the same. It starts no run.

The Webhook block offers these WooCommerce topics: `order.created`, `order.updated`, `order.deleted`, `order.restored`, `product.created`, `product.updated`, `product.deleted`, `customer.created`, `customer.updated`, `customer.deleted`, `coupon.created`, and `coupon.updated`.

## Save the Secret

WooCommerce signs each request with the secret from the webhook's form. The same value lets OutWin check that signature.

1. In OutWin, paste the secret into **Secret** in the block's settings.
2. Select **Save**.

After you save, the settings show only the last four characters of the secret, with **Replace** and **Remove**. Under **Set up**, the second line changes to "The secret is saved: deliveries are verified."

OutWin saves the secret on the block's URL. It is not saved on a connection. A second Webhook block has its own URL and its own secret.

WooCommerce's signature carries no time, and its requests carry no event id. A saved copy of a signed request that is sent again passes the check and starts a run each time.

Without a saved secret the block still starts runs, and nothing is verified: anyone who has the URL can start the workflow. Publishing then shows a warning that ends "has no signing secret saved, so its deliveries are not verified: anyone who has this URL can start this workflow". The warning does not block publishing.

## Choose which events start a run

Under **Events that start a run**, tick the topics that start a run. With none ticked, every event WooCommerce sends starts a run. To start runs for a topic that is not listed, type it into the box under the list and select **Add**.

An event whose topic is not ticked is listed as **Filtered out** and starts no run. To narrow further by a field of the event, add a row under **Only when**. The body is the order, product, customer, or coupon itself, so an order's status has the path `body.status`. [Webhook settings](https://outwin.ai/docs/reference/triggers-approvals-and-waits/#webhook-settings) lists the comparisons.

## Send a test and check what arrived

1. In the store, do something that causes the webhook's topic, such as placing a test order.
2. In OutWin, look under **Recent deliveries** in the block's settings.

**Recent deliveries** lists every event that reached the URL, including while the workflow is a draft. On a draft each event is listed as **Dropped** with "The workflow is not published, so nothing ran." It starts no run and is not run later. The last line under **Set up** changes from "WooCommerce checked that the URL answers." to, for example, "Received order.created. Dropped."

With a secret saved, an event listed as **Dropped** on a draft has passed the signature check. A delivery that fails the check is listed as **Refused**.

If you have edit access, select an event to see what the block passed on. The list is kept for seven days, and the data of the newest 20 events is kept.

## Read the event in the next block

Each run receives one WooCommerce event. WooCommerce puts the topic in a request header, so the body is the order, product, customer, or coupon itself and does not say what happened to it. Read the topic from `event`. An HTTP request block or a database block directly after the Webhook block reads the event with these expressions. An AI block such as **Think** receives the whole value as its input.

| Expression | What it holds |
| --- | --- |
| `{{input.body}}` | The object as WooCommerce sent it: the order for an `order.created` event, for example. Its fields depend on the topic. For a deleted object the body holds only its `id`. |
| `{{input.body.id}}` | One field of the object. Read any other field the same way. |
| `{{input.event.type}}` | The topic, such as `order.created`. It is the request's `X-WC-Webhook-Topic` header. |
| `{{input.event.id}}` | Empty. WooCommerce sends no id for an event. |
| `{{input.event.time}}` | The time the object was last changed, as an ISO 8601 date and time. It is read from the body's `date_modified_gmt` field, or `date_created_gmt` when that is absent. Empty when the body has neither, as for a deleted object. `{{input.delivery.receivedAt}}` holds the time the request arrived. |
| `{{input.delivery.verified}}` | `true` only when the signature was checked and passed. |

A block further along reads the same values through the Webhook block's name, as in `{{steps["WooCommerce"].body.id}}` for a block named `WooCommerce`. [Data and context](https://outwin.ai/docs/reference/data-and-context/) describes what each block passes on.

## Publish and check the runs

[Publish the workflow](https://outwin.ai/docs/run/publish-and-start/). From then on, each event that passes the filter starts a run. On a published workflow the block's settings are read-only, and **Recent deliveries** is in the block's inspector. You can still replace the secret there.

| Outcome | What happened |
| --- | --- |
| **Ran** | The event started a run. |
| **Waiting** | 10 runs of the workflow are already active. The event starts a run when one of them ends. An event that waits longer than an hour is listed as **Dropped**. |
| **Handshake** | WooCommerce's check of the URL when the webhook was saved as **Active**. It starts no run. |

The block does not skip duplicates for WooCommerce, because a request carries nothing that identifies its event. Two requests for the same change start two runs. If a second run would do harm, such as sending a customer the same message twice, have the workflow check a database for the order's `id` before it acts.

Runs start in the order events arrive. That is not always the order things happened, so do not build a workflow that relies on `order.created` arriving before `order.updated`.

Receiving an event costs no credits, and neither does an event that is filtered out or a handshake. A run that starts uses credits for the blocks that run in it.

## If nothing runs

Open **Recent deliveries** and read the outcome and the sentence beside the newest event.

| What you see | Cause | Fix |
| --- | --- | --- |
| "Nothing has arrived yet." | No request has reached the URL, not even the check WooCommerce makes when the webhook is saved. | Check that the webhook's **Status** is **Active** and that **Delivery URL** is the block's current URL. **Rotate token** on a published workflow changes the URL, and the old one stops working. |
| **Handshake** and nothing else | WooCommerce reached the URL, and nothing has caused the webhook's topic since. | Check the webhook's **Topic**, and cause it again. |
| **Dropped** with "The workflow is not published, so nothing ran." | The workflow is a draft. | Publish the workflow. Events that arrived before then are not run later. |
| **Dropped** with "The workflow is paused, so nothing ran." | The workflow is paused. | Resume the workflow. Events that arrived while it was paused are not run later. |
| **Filtered out** with `Events of type "order.updated" are not chosen on this trigger.` | The event's topic is not ticked under **Events that start a run**. | Tick the topic, or clear every tick so that all events start a run. The settings are read-only on a published workflow. |
| **Refused** with "The signature did not match. Check that the secret saved here is the one the sender shows for this URL." | The saved secret is not the value in the webhook's **Secret** field. This can happen when the field was left empty, when two webhooks that send to this block have different secrets, or when the secret has characters WordPress stored differently. | Enter a secret of letters and digits in **Secret** on every webhook that sends to this block, save each webhook, and select **Replace** in OutWin with the same value. You do not republish the workflow. |
| **Refused** with "The request carried no signature." | A secret is saved in OutWin, and the request did not carry WooCommerce's signature. A request sent by hand to try the URL has none. | Cause the event in the store so that WooCommerce sends the request. |
| Deliveries stopped after several were **Refused** | WooCommerce turns a webhook off after more than five deliveries in a row fail, and a delivery listed as **Refused** counts as failed. | Fix the secret, then set the webhook's **Status** back to **Active** in WooCommerce. |

A delivery listed as **Refused** is answered with status `401` and starts nothing. OutWin keeps none of its data, and WooCommerce does not send a failed delivery again. For every other outcome in the table, WooCommerce receives a success response and OutWin does not run the event later.
