> For the complete documentation index, see [llms.txt](https://docs.webtonative.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.webtonative.com/javascript-apis/webtonative-notifications/webhook-connectors/wordpress-connector.md).

# Wordpress Connector

Send automatic push notifications to your app users when something happens in your WooCommerce store, like a new order, an order update or a new coupon.

This guide connects your WooCommerce store to WebToNative with a webhook, and links each logged-in WordPress user to their device so every notification reaches the right person.

> **Platform support:** Android and iOS.

> **Before you start:**
>
> * Your plan must include **WebToNative Push**.
> * Push must be configured for your app (Android and/or iOS) in the WebToNative dashboard.
> * The **WebToNative WordPress plugin** must be installed on your site. See the [WordPress Plugin Guide](https://docs.webtonative.com/website-plugins/wordpress.md).

***

## How it works

1. **Link users to devices.** The WebToNative plugin calls `WTN.Notification.setExternalUserId()` with the WordPress user ID when a user is logged in, and `removeExternalUserId()` when they log out.
2. **WooCommerce sends a webhook.** When the event happens (for example, an order is created), WooCommerce sends the order data to your connector's webhook URL.
3. **WebToNative sends the notification.** We read the user ID from the webhook (`customer_id`) and send your notification to every device linked to that user.

***

## 1. Enable User Sync in the plugin

### Step 1: Open the Push Notification settings

1. Log in to your WordPress admin dashboard.
2. Go to **webtonative > Push Notification**.

### Step 2: Turn on User Sync

1. Tick **Enable User Sync**.
2. Click **Save Changes**.

From now on, the logged-in WordPress user is linked to the device (`WTN.Notification.setExternalUserId`), and unlinked when they log out.

> **Users who were already logged in** are linked the next time they open or refresh a page in the app. They don't need to log in again.

***

## 2. Create the connector in WebToNative

### Step 1: Open Webhook Connector

1. Log in to the WebToNative dashboard.
2. Go to **My Apps** and select your app.
3. In the sidebar, open **Push Notification > Webhook Connector**.

<figure><img src="https://46162361-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbRbEDU7JrvMAgg52AY%2Fuploads%2FShRmDDM4hA5E7kp8t3nA%2Fwebhook-connector-page.png?alt=media&amp;token=ba1c8d81-a2d2-4f21-839c-ff7105e1a398" alt=""><figcaption></figcaption></figure>

### Step 2: Add a WordPress connector

1. Click **+ Connect Webhook** (or **+ Add Connector** if you already have connectors).
2. Select **WordPress** and click **Continue**.

<figure><img src="https://46162361-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbRbEDU7JrvMAgg52AY%2Fuploads%2FzZVsNUfTDwyDqvkNNLGk%2Fimage.png?alt=media&amp;token=7bd3d412-7bc8-42bc-bf54-b449c3f2c8da" alt=""><figcaption></figcaption></figure>

3\. Enter a \*\*Connector Name\*\*, for example \`Order created\`. 4. Copy the \*\*Webhook URL\*\* and the \*\*Secret Code\*\*. You'll paste both into WooCommerce in the next section.

Keep this window open. You'll come back to click **Verify**.

> Need a new secret? Click **Regenerate Secret** above the Secret Code, and use the new one in WooCommerce.

***

## 3. Add the webhook in WooCommerce

### Step 1: Open WooCommerce webhooks

1. In WordPress admin, go to **WooCommerce > Settings > Advanced > Webhooks**.
2. Click **Add webhook**.

### Step 2: Fill in the webhook

| Field            | Value                                                 |
| ---------------- | ----------------------------------------------------- |
| **Name**         | Any name, e.g. `WebToNative - Order created`          |
| **Status**       | `Active`                                              |
| **Topic**        | The event this connector is for, e.g. `Order created` |
| **Delivery URL** | The **Webhook URL** from your connector               |
| **Secret**       | The **Secret Code** from your connector               |
| **API Version**  | `WP REST API Integration v3`                          |

Click **Save webhook**.

> **Don't leave the Secret field empty.** If it's empty, WooCommerce creates its own secret and WebToNative can't verify the webhook.

***

## 4. Verify the connector

### Step 1: Click Verify

1. Back in WebToNative, tick **Yes, I have saved the webhook in WooCommerce with this URL and secret code**.
2. Click **Verify**.

<figure><img src="https://46162361-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbRbEDU7JrvMAgg52AY%2Fuploads%2FUYRgESiud9xvYe36rWon%2Fwordpress-add-connector-secret.png?alt=media&amp;token=b806971e-b327-414a-a9ba-2ffd56740c9d" alt=""><figcaption></figcaption></figure>

The connector is saved and the window shows **Waiting for the test event**.

### Step 2: Trigger the event in WooCommerce

WooCommerce has no test button, so trigger the event once. For example, place a test order for an **Order created** connector.

<figure><img src="https://46162361-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbRbEDU7JrvMAgg52AY%2Fuploads%2FR85cWzYP0JMDP9G6NIqz%2Fwordpress-waiting-for-test-event.png?alt=media&amp;token=a85b5ea4-852a-4a10-89a0-21931ee23d71" alt=""><figcaption></figcaption></figure>

When WebToNative receives the event and the secret matches, the connector status changes to **Active**.

> **You can close this window.** The connector stays in the list as **Pending verification** and verifies automatically once the event arrives. No notifications are sent until it's **Active**.

> **One connector = one webhook.** To send notifications for another event (for example, Order updated), add a new connector in WebToNative and a new webhook in WooCommerce with that connector's URL and secret.

***

## 5. Create the notification template

After the connector is verified, the **Create a Template** window opens. You can also open it later from the **⋯** menu on the connector row > **Edit Template**.

1. **Connector Name** is filled in and can't be changed here.
2. Enter a **Title** for the notification.
3. Enter the **Message**. Click **Available variables** `{ }` to insert values from the webhook.
4. Enter a **Launch URL**: the page that opens when the user taps the notification (optional). It can be a fixed URL, like `https://yourstore.com/orders`, or a variable.
5. Check the phone preview, then click **Save Template**.

<figure><img src="https://46162361-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbRbEDU7JrvMAgg52AY%2Fuploads%2F3eKOvdtZMziXlm7yxTho%2Fcreate-template.png?alt=media&amp;token=c05cfc28-6111-4586-b16c-f88e53ac3d30" alt=""><figcaption></figcaption></figure>

### Using variables

Insert values from the WooCommerce webhook with `{{field}}`. Open **Available variables** in the template to pick one.

| Variable                 | Value from WooCommerce | Example      |
| ------------------------ | ---------------------- | ------------ |
| `{{id}}`                 | Order ID               | `1234`       |
| `{{number}}`             | Order number           | `1234`       |
| `{{status}}`             | Order status           | `processing` |
| `{{total}}`              | Order total            | `1499.00`    |
| `{{currency}}`           | Currency               | `INR`        |
| `{{customer_id}}`        | WordPress user ID      | `42`         |
| `{{billing.first_name}}` | Customer first name    | `Asha`       |

**Example:**

* Title: `Order received`
* Message: `Hi {{billing.first_name}}, your order #{{number}} of {{currency}} {{total}} is confirmed.`

***

## 6. Manage your connectors

### Connector status

| Status                   | Meaning                                                                            |
| ------------------------ | ---------------------------------------------------------------------------------- |
| **Pending verification** | Created, but no valid webhook received yet. No notifications are sent.             |
| **Active**               | Verified and sending notifications.                                                |
| **Paused**               | Turned off with the **Enabled** toggle. Webhooks are received but nothing is sent. |

### Row actions

Open the **⋯** menu on a connector row:

* **Analytics**: Events Received, Notification Sent, Notification Skipped and CTR for this connector.
* **Edit Template**: change the title, message or Launch URL.
* **Delete**: remove the connector. Also delete its webhook in WooCommerce.

Use the **Enabled** toggle to pause or resume a connector.

***

## 7. Troubleshooting

* **Connector stays Pending verification**
  * Make sure the webhook's **Status** is `Active` in WooCommerce.
  * Check that the **Delivery URL** and **Secret** are exactly the ones from your connector.
  * Trigger the event once (for example, place a test order).
* **"You don't have any users yet" banner**
  * Turn on **Enable User Sync** in **webtonative > Push Notification**.
  * Log in on the app once so the user is linked to the device.
* **Notification Skipped increases**
  * The order was placed by a guest (`customer_id` is `0`), so there is no user to send it to.
  * The user hasn't opened the app while logged in, so their device isn't linked yet.
  * The connector is **Paused**, or it has no template.
* **Users are not linked**
  * Open the site inside the WebToNative app, not in a browser.
  * Check the browser console for errors related to `WTN.Notification`.

***

**Notes:**

* Notifications are sent only to users who are logged in on the app at least once with **Enable User Sync** turned on.
* The user ID in the webhook (`customer_id`) must match the WordPress user ID linked by the plugin. This works automatically when you use the plugin.
* Need help? Email <support@webtonative.com> or visit [webtonative.com/support](https://www.webtonative.com/support).
