# WooCommerce order status on WhatsApp with webhooks, no plugin

> Turn WooCommerce order.updated webhooks into WhatsApp utility messages, verify the signature, plan for no retries, and write replies back as private notes.

Published 2026-11-25. Z-API Omni team.

Point one WooCommerce webhook with topic `order.updated` at your service and verify `X-WC-Webhook-Signature`. Then send a WhatsApp utility template only when the order's status differs from the last one you messaged. WooCommerce sends no previous status, and the docs describe no retries. Answer every delivery with a fast 2xx and store the last status yourself. Customer replies go back as private order notes through the REST API.

The reply loop (quick-reply payloads, matching on `context.id`, conditional updates, silence) is in [WhatsApp order confirmation with Confirm and Cancel buttons](/academy/articles/whatsapp-order-confirmation-confirm-cancel-buttons/). The Shopify version is [Shopify order webhooks to WhatsApp](/academy/articles/shopify-order-webhook-whatsapp-notifications/). This page covers what WooCommerce does differently, based on its docs and on the core source in [`class-wc-webhook.php`](https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/plugins/woocommerce/includes/class-wc-webhook.php) (trunk, read 2026-11-25).

## Create the webhook

Use WooCommerce > Settings > Advanced > Webhooks, or the REST API. The order topics are "`order.created`, `order.updated` and `order.deleted`" ([REST API webhooks, accessed 2026-11-25](https://developer.woocommerce.com/docs/apis/rest-api/v3/webhooks/)), and the source adds `order.restored`.

```bash
curl -X POST "$WC_URL/wp-json/wc/v3/webhooks" \
  -u "$WC_KEY:$WC_SECRET" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "Order updated to WhatsApp",
  "topic": "order.updated",
  "delivery_url": "https://hooks.example.com/woo/webhook",
  "secret": "'"$WC_WEBHOOK_SECRET"'"
}'
```

Pick a secret without `&`, `<`, `>` or quotes. The source signs with `wp_specialchars_decode()` applied to the stored secret, so HTML entities in it would change the key.

### Why order.updated, not order.created

The block checkout creates the order as `checkout-draft` first, and the webhook code skips drafts (`DRAFT`, `AUTO_DRAFT`, `CHECKOUT_DRAFT`, `NEW`). Our reading of the source is that the first delivery for a real order can therefore arrive as `order.updated`. We haven't confirmed this on a live store. Subscribing to `order.updated` and keying off `status` works either way.

<!-- TODO:test: with block checkout, whether order.created fires for a paid order or only order.updated -->

## What a delivery looks like

Each delivery is a POST with headers `X-WC-Webhook-Source`, `-Topic`, `-Resource`, `-Event`, `-Signature`, `-ID` and `-Delivery-ID`. The body is `trim( wp_json_encode( $payload ) )`. The signature is `base64_encode( hash_hmac( 'sha256', $payload, wp_specialchars_decode( $secret, ENT_QUOTES ), true ) )` over that body. SHA-256 is the default, and a filter can change it.

Verify over the raw bytes. The signature covers no timestamp, and the delivery ID is a hash of the webhook ID and the current second. Neither helps with dedupe, so build your own key from order ID, status and `date_modified_gmt`.

### The activation ping has no signature

When a webhook is saved as active, WooCommerce sends a ping with the form-encoded body `webhook_id=<ID>` and no signature header. A non-2xx response produces "Error: Delivery URL returned response code". Answer the ping with 200 and do nothing else. Rejecting it for the missing signature blocks activation.

### The payload is built when it is delivered

Deliveries run asynchronously through Action Scheduler by default. When the job runs, `deliver()` calls `build_payload()`, which reads the order from `/wc/v3/orders/<id>` at that moment. The body shows the order as it is at delivery time, not at the event. A code comment in the source also reads "Make webhooks unique - only schedule one webhook every 10 minutes".

Two quick status changes can therefore arrive as one delivery, or as two that both show the latest status. The payload has no field for the previous status. Store the status you last messaged per order, and act only when the new one differs. The same rule absorbs your own writes: a `PUT` to `cancelled` fires `woocommerce_update_order`, and your service receives that change as a webhook. Ordering in general is covered in [out-of-order webhooks](/academy/articles/whatsapp-webhooks-out-of-order-message-sequencing/).

### No retries, and five failures disable it

The core code shows no retry. Failed deliveries only count toward a limit: `if ( $failures > apply_filters( 'woocommerce_max_webhook_delivery_failures', 5 ) )`, and the webhook's status becomes `disabled`. The docs say the same: "After 5 consecutive failed deliveries (as defined by a non HTTP 2xx response code)", after which you re-enable it through REST.

Return 2xx before any WhatsApp call, and queue the work. Run a cron job that reads the webhook's `status` and alerts when it reads `disabled`. Neither the docs nor the core code describe a resend, so a reconciliation pass over recently changed orders closes the gap. The idempotency pattern is in [duplicate webhooks and idempotency](/academy/articles/n8n-duplicate-webhooks-idempotency/).

## Map each status to one utility message

Every message below is about the customer's own order and contains no offer, which keeps it inside Meta's utility definition. Meta treats "an order update with a promo" as marketing ([template categorization, accessed 2026-11-25](https://developers.facebook.com/documentation/business-messaging/whatsapp/templates/template-categorization)). The `status` values come from the REST API ([orders, accessed 2026-11-25](https://developer.woocommerce.com/docs/apis/rest-api/v3/orders/)).

| Status | Template | Template Library match | Content |
| --- | --- | --- | --- |
| `processing` | `order_confirm_v1` | `ORDER_CONFIRMATION` | Number, total, Confirm and Cancel quick replies |
| `on-hold` | `order_on_hold_v1` | None named | "Order {{order_number}} is on hold until we receive payment." |
| `completed` | `order_shipped_v1` | `SHIPMENT_CONFIRMATION` | Carrier and a tracking URL button |
| `cancelled` | `order_cancelled_v1` | `ORDER_OR_TRANSACTION_CANCEL` | "Order {{order_number}} has been cancelled." |

`order_confirm_v1` is created in the order confirmation article, and `order_shipped_v1` in the Shopify one. Create the other two the same way, as `UTILITY` with one named parameter. Keep the on-hold text factual. A payment reminder with pressure wording is a different message with different rules. Two store messages outside this table have their own pages: [back-in-stock alerts](/academy/articles/whatsapp-back-in-stock-alert-customer-asked/), which are marketing, and [return and refund updates](/academy/articles/whatsapp-return-refund-status-updates/), which stay utility.

## Capture WhatsApp consent at checkout

WooCommerce has no WhatsApp consent field. On the block checkout, register one with `woocommerce_register_additional_checkout_field` on `woocommerce_init` ([additional checkout fields, accessed 2026-11-25](https://developer.woocommerce.com/docs/block-development/cart-and-checkout-blocks/additional-checkout-fields)). The label must name the store and say what the customer gets, per [WhatsApp opt-in rules](/academy/articles/whatsapp-opt-in-how-to-collect-consent/). This goes in your theme's `functions.php` or a small site plugin you own.

```php
<?php
add_action( 'woocommerce_init', function () {
    if ( ! function_exists( 'woocommerce_register_additional_checkout_field' ) ) {
        return;
    }
    woocommerce_register_additional_checkout_field( array(
        'id'       => 'yourstore/whatsapp-updates',
        'label'    => 'Send me order updates from YOUR_STORE_NAME on WhatsApp',
        'location' => 'contact',
        'type'     => 'checkbox',
    ) );
} );
```

The value is stored as order meta `_wc_other/yourstore/whatsapp-updates`, with checkbox values `"1"`, `"0"` or `""`. WooCommerce's docs don't say whether that key appears in the REST `meta_data` that the webhook payload carries. The service below reads it from `meta_data` and sends nothing when it is missing, which fails safe. The classic shortcode checkout needs checkout hooks instead.

<!-- TODO:test: whether _wc_other/<namespace>/<field> appears in the order.updated payload meta_data -->

### The phone is free text

`billing.phone` is a plain string, and the v3 order table lists no `shipping.phone`. Normalize it with `billing.country` before sending, as described in [WhatsApp phone number format](/academy/articles/whatsapp-phone-number-format-e164-normalization/).

## Write the reply back as a private note

Add a note with `POST /wp-json/wc/v3/orders/<id>/notes` and a body of `{"note": "..."}` ([order notes, accessed 2026-11-25](https://developer.woocommerce.com/docs/apis/rest-api/v3/order-notes/)). Set `customer_note` to false. With `true`, "the note will be shown to customers and they will be notified", so the customer would get an email about their own tap. Whether adding a note fires `order.updated` is untested. The status guard absorbs it if it does.

<!-- TODO:test: whether POST /orders/<id>/notes triggers order.updated -->

Cancel with `PUT /wp-json/wc/v3/orders/<id>` and `{"status": "cancelled"}`. WooCommerce enforces no cancellation window, so the guard lives in your code. Allow a cancel only while the status is `pending`, `on-hold` or `processing`, and check your shipping plugin if it marks shipments separately.

Cancelling doesn't refund the payment. On `woocommerce_order_status_cancelled`, core calls `wc_maybe_increase_stock_levels`, which restores stock only when the order carries the `_order_stock_reduced` flag ([wc-stock-functions.php, read 2026-11-25](https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/plugins/woocommerce/includes/wc-stock-functions.php)). Refunds are a separate step, so a cancel tap on a paid order should also reach a person.

## The complete service

This Node 18+ file runs with `npm install express`. It answers the ping, verifies both webhooks, sends one message per status change, and handles taps. Keep `lastStatus` in a table in production, or a restart resends the current status.

```js
// woo-whatsapp.js. Node 18+. npm install express
const crypto = require("crypto");
const express = require("express");

const {
  WC_URL, WC_KEY, WC_SECRET, WC_WEBHOOK_SECRET,
  WA_TOKEN, PHONE_NUMBER_ID, APP_SECRET, VERIFY_TOKEN,
  CONSENT_META_KEY = "_wc_other/yourstore/whatsapp-updates",
  COUNTRY_CODES = '{"US":"1","GB":"44","ES":"34","MX":"52","BR":"55"}',
  CARRIER_NAME = "our carrier", PORT = "3000",
} = process.env;

const GRAPH_URL = `https://graph.facebook.com/v26.0/${PHONE_NUMBER_ID}/messages`;
const CALLING_CODES = JSON.parse(COUNTRY_CODES);
const CANCELLABLE = new Set(["pending", "on-hold", "processing"]);

const lastStatus = new Map();   // order id -> status we last acted on
const seenEvents = new Set();   // `${id}:${status}:${date_modified_gmt}`
const byWamid = new Map();      // template wamid -> order id
const answered = new Map();     // order id -> "confirm" | "cancel"
const seenMessages = new Set(); // Meta messages[].id

const rawBuffer = (req) => (Buffer.isBuffer(req.body) ? req.body : Buffer.alloc(0));
const safeEqual = (a, b) => {
  const x = Buffer.from(a ?? ""), y = Buffer.from(b ?? "");
  return x.length === y.length && crypto.timingSafeEqual(x, y);
};
const handOff = (orderId, reason, detail) => console.log("needs_person", { orderId, reason, detail });

const wcAuth = "Basic " + Buffer.from(`${WC_KEY}:${WC_SECRET}`).toString("base64");
async function wc(method, path, body) {
  const res = await fetch(`${WC_URL}/wp-json/wc/v3${path}`, {
    method,
    headers: { Authorization: wcAuth, "Content-Type": "application/json" },
    body: body ? JSON.stringify(body) : undefined,
  });
  if (!res.ok) throw new Error(`wc ${method} ${path} ${res.status}`);
  return res.json();
}
const addNote = (id, note) => wc("POST", `/orders/${id}/notes`, { note, customer_note: false });

async function waSend(body) {
  const res = await fetch(GRAPH_URL, {
    method: "POST",
    headers: { Authorization: `Bearer ${WA_TOKEN}`, "Content-Type": "application/json" },
    body: JSON.stringify({ messaging_product: "whatsapp", ...body }),
  });
  const json = await res.json();
  if (!res.ok) throw new Error(`Graph ${res.status}: ${JSON.stringify(json.error ?? json)}`);
  return json.messages[0].id;
}
const waText = (to, text) => waSend({ to, type: "text", text: { body: text } });
const named = (pairs) => Object.entries(pairs).map(([k, v]) => ({ type: "text", parameter_name: k, text: String(v) }));
const template = (to, name, components) => ({ to, type: "template", template: { name, language: { code: "en_US" }, components } });
const quickReply = (index, payload) => ({ type: "button", sub_type: "quick_reply", index, parameters: [{ type: "payload", payload }] });

function normalizePhone(raw, country) {
  if (!raw || /[a-z]/i.test(raw)) return null;
  const digits = raw.replace(/\D/g, "");
  if (raw.trim().startsWith("+")) return digits.length >= 8 ? digits : null;
  const code = CALLING_CODES[country];
  return code && digits.length >= 6 ? code + digits.replace(/^0+/, "") : null;
}

const hasConsent = (order) =>
  (order.meta_data ?? []).some((m) => m.key === CONSENT_META_KEY && String(m.value) === "1");

const MESSAGES = {
  processing: (o, to) => template(to, "order_confirm_v1", [
    { type: "body", parameters: named({ customer_name: o.billing?.first_name || "there", order_number: o.number, order_total: `${o.total} ${o.currency}` }) },
    quickReply(0, `confirm:${o.id}`),
    quickReply(1, `cancel:${o.id}`),
  ]),
  "on-hold": (o, to) => template(to, "order_on_hold_v1", [
    { type: "body", parameters: named({ order_number: o.number }) },
  ]),
  completed: (o, to) => template(to, "order_shipped_v1", [
    { type: "body", parameters: named({ order_number: o.number, carrier: CARRIER_NAME }) },
    { type: "button", sub_type: "url", index: 0, parameters: [{ type: "text", text: String(o.id) }] },
  ]),
  cancelled: (o, to) => template(to, "order_cancelled_v1", [
    { type: "body", parameters: named({ order_number: o.number }) },
  ]),
};

async function onOrder(order) {
  const key = `${order.id}:${order.status}:${order.date_modified_gmt}`;
  if (seenEvents.has(key)) return;
  seenEvents.add(key);
  if (lastStatus.get(order.id) === order.status) return; // no change, or our own write echoing back
  lastStatus.set(order.id, order.status);

  const build = MESSAGES[order.status];
  if (!build || !hasConsent(order)) return;
  const phone = normalizePhone(order.billing?.phone, order.billing?.country);
  if (!phone) return handOff(order.id, "no_usable_phone", null);

  const wamid = await waSend(build(order, phone));
  byWamid.set(wamid, order.id);
  await addNote(order.id, `WhatsApp "${order.status}" message sent (${wamid}).`).catch((err) => handOff(order.id, "note_failed", err.message));
}

async function onTap(msg) {
  if (seenMessages.has(msg.id)) return;
  seenMessages.add(msg.id);
  const orderId = byWamid.get(msg.context?.id);
  if (!orderId) return handOff(null, "unmatched_message", { id: msg.id, type: msg.type });
  if (msg.type !== "button") return handOff(orderId, "free_text", msg.text?.body ?? msg.type);

  const [verb] = String(msg.button?.payload ?? "").split(":");
  const label = String(msg.button?.text ?? "").toLowerCase();
  const action = verb === "confirm" || label === "confirm order" ? "confirm"
    : verb === "cancel" || label === "cancel order" ? "cancel" : null;
  if (!action) return handOff(orderId, "unreadable_button", msg.button);

  const order = await wc("GET", `/orders/${orderId}`);
  const phone = normalizePhone(order.billing?.phone, order.billing?.country);
  if (answered.has(orderId)) {
    return waText(phone, `Order ${order.number} was already handled. Reply here if that looks wrong.`);
  }

  if (action === "confirm") {
    answered.set(orderId, "confirm");
    await addNote(orderId, "Customer confirmed the order on WhatsApp.").catch((err) => handOff(orderId, "note_failed", err.message));
    return waText(phone, `Thanks. Order ${order.number} is confirmed.`);
  }

  if (!CANCELLABLE.has(order.status)) {
    handOff(orderId, "cancel_not_allowed", order.status);
    return waText(phone, `Order ${order.number} can no longer be cancelled here. A person from our team will reply.`);
  }
  answered.set(orderId, "cancel");
  lastStatus.set(order.id, "cancelled"); // so the echo of our own PUT sends no template
  try {
    await wc("PUT", `/orders/${orderId}`, { status: "cancelled" });
  } catch (err) {
    answered.delete(orderId);
    lastStatus.set(order.id, order.status);
    handOff(orderId, "cancel_failed", err.message);
    return waText(phone, `We got your request for order ${order.number}. A person from our team will confirm it here.`);
  }
  await addNote(orderId, "Customer cancelled the order on WhatsApp.").catch((err) => handOff(orderId, "note_failed", err.message));
  if (order.status !== "pending") handOff(orderId, "check_refund", order.total); // cancel does not refund
  return waText(phone, `Order ${order.number} is cancelled. Reply here if you have a question about it.`);
}

const app = express();

app.post("/woo/webhook", express.raw({ type: "*/*" }), (req, res) => {
  const buf = rawBuffer(req);
  const signature = req.get("x-wc-webhook-signature");
  if (!signature && /^webhook_id=\d+$/.test(buf.toString("utf8").trim())) {
    return res.sendStatus(200); // activation ping: unsigned, form-encoded
  }
  const digest = crypto.createHmac("sha256", WC_WEBHOOK_SECRET).update(buf).digest("base64");
  if (!safeEqual(digest, signature)) return res.sendStatus(401);
  res.sendStatus(200);

  const topic = req.get("x-wc-webhook-topic");
  if (topic !== "order.updated" && topic !== "order.created") return;
  const order = JSON.parse(buf.toString("utf8"));
  onOrder(order).catch((err) => handOff(order.id, "order_event_failed", err.message));
});

app.get("/whatsapp/webhook", (req, res) => {
  const ok = req.query["hub.mode"] === "subscribe" && req.query["hub.verify_token"] === VERIFY_TOKEN;
  return ok ? res.send(req.query["hub.challenge"]) : res.sendStatus(403);
});

app.post("/whatsapp/webhook", express.raw({ type: "application/json" }), (req, res) => {
  const buf = rawBuffer(req);
  const expected = "sha256=" + crypto.createHmac("sha256", APP_SECRET).update(buf).digest("hex");
  if (!safeEqual(expected, req.get("x-hub-signature-256"))) return res.sendStatus(401);
  res.sendStatus(200);
  const body = JSON.parse(buf.toString("utf8"));
  for (const entry of body.entry ?? []) {
    for (const change of entry.changes ?? []) {
      for (const msg of change.value?.messages ?? []) {
        onTap(msg).catch((err) => handOff(null, "tap_failed", err.message));
      }
    }
  }
});

app.listen(Number(PORT), () => console.log(`listening on ${PORT}`));
```

`COUNTRY_CODES` maps the ISO country in `billing.country` to a calling code. Extend it for the countries you sell to. The Meta side follows [X-Hub-Signature-256 verification](/academy/articles/whatsapp-webhook-signature-verification-x-hub-signature-256/).

## When something fails

If the WhatsApp send throws after the 2xx, the error goes to a person, and the status is already recorded. WooCommerce wouldn't have retried anyway. If your service is down, deliveries fail and count toward the five that disable the webhook. Your cron check and the reconciliation pass are the only recovery.

A customer who doesn't tap keeps their order as it is. The service never cancels on silence. Port the no-reply handling from the order confirmation article. A Cancel tap on a `completed` order gets a reply and a hand-off, never a status change.

## Where Z-API Omni fits

Omni documents no WooCommerce integration, so the service above remains the bridge. On the WhatsApp side, the same templates go through `POST https://api.omni.z-api.io/v1/channels/{channelId}/messages` with a `Bearer` Secret Key, and its docs include the quick-reply payload component. The inbound shape of a tap isn't documented yet. One subscription covers WhatsApp, Messenger, Instagram and Telegram, so a store-owner alert on Telegram can run from the same account. Pricing is per number: US$29 per month for 1 to 10 numbers, US$26 for 11 to 50, US$23 for 51 to 100, US$20 above 100. The QR connection has no per-message cost, and Meta's fees pass through on Meta's official API.

[View documentation](https://developer.omni.z-api.io/en)

*Z-API Omni team*
