Updated on October 29, 2026
To connect WooCommerce to the official WhatsApp Business API, you listen for order status changes (with the PHP hook woocommerce_order_status_changed or a WooCommerce webhook) and, for each event, send a Meta-approved template to the customer’s phone. Order confirmation, payment received and shipping updates are utility templates; abandoned cart reminders are marketing. The customer must have agreed to receive these messages, and a checkbox at checkout is the natural place to ask.
Why to avoid “pirate” WhatsApp plugins
Many WhatsApp plugins for WooCommerce connect your number by scanning a QR code, as if it were WhatsApp Web. That is not the official API: the number can be banned, and there are no approved templates and no status webhooks. If the plugin is a “nulled” copy of a paid product, you are also installing code of unknown origin on the server that stores your customers’ data. Our article on official vs. unofficial WhatsApp API covers the risks in detail.
With the official WhatsApp API, the store sends Meta-approved templates, gets the status of every message and pays per delivered message at a public rate.
The two integration paths
| Path | How it works | When to use it |
|---|---|---|
| PHP hook inside WordPress | A small custom plugin listens to woocommerce_order_status_changed and calls the API | Single store, someone on the team maintains PHP |
| WooCommerce webhook | WooCommerce posts the order as JSON to your backend, n8n or Make | Logic outside WordPress, several stores, team that avoids PHP |
The PHP hook has fewer moving parts; the webhook moves sending out of WordPress and makes it easier to reuse the same logic for other platforms, such as Shopify and Nuvemshop/Tiendanube.
Want to try it while you read? Create a Vectalk account and send your first message through the official API. Create free account →
Path 1: the woocommerce_order_status_changed hook
WooCommerce fires woocommerce_order_status_changed whenever an order moves from one status to another. The WooCommerce code reference shows its four arguments: order ID, old status, new status and the order object. There are also per-status hooks, such as woocommerce_order_status_processing, and woocommerce_payment_complete, fired when payment is confirmed.
The built-in statuses that matter for notifications:
| Status (slug) | In the admin | Suggested notification | Category |
|---|---|---|---|
pending | Pending payment | Bank transfer, Pix or boleto issued, awaiting payment | Utility, if the text is only about the order |
on-hold | On hold | Payment under review or awaiting confirmation | Utility |
processing | Processing | Payment received, order being prepared | Utility |
completed | Completed | Order shipped or delivered, with tracking | Utility |
cancelled / failed | Cancelled / Failed | Order cancelled or payment declined | Utility |
Which status an order paid by bank transfer, Pix (Brazil’s instant payment system) or boleto (a Brazilian bank payment slip) lands in depends on the payment gateway: place a test order with each method before mapping templates. Also check that the hook actually fires: when an order is created directly in its final status, with no change from one status to another, woocommerce_order_status_changed may not be called.
PHP example
A minimal plugin: it maps statuses to templates, normalizes the phone number, respects opt-in and stores a flag on the order once the notification goes out, so it is never sent twice.
<?php
/* Plugin Name: WhatsApp order notifications */
defined( 'ABSPATH' ) || exit;
const VT_API_URL = 'https://apis.vectalk.com.br/api/messages';
// WooCommerce status => template approved by Meta
function vt_templates() {
return array(
'pending' => 'order_awaiting_payment',
'processing' => 'order_payment_received',
'completed' => 'order_shipped',
);
}
add_action( 'woocommerce_order_status_changed', 'vt_on_status_changed', 10, 4 );
function vt_on_status_changed( $order_id, $from, $to, $order ) {
$templates = vt_templates();
$flag = '_vt_whatsapp_' . $to;
$phone = vt_normalize_phone( $order->get_billing_phone() );
if ( ! isset( $templates[ $to ] ) || ! $phone || ! vt_has_optin( $order ) || $order->get_meta( $flag ) ) {
return; // no template, no phone, no opt-in, or already notified
}
$body = array(
'messaging_product' => 'whatsapp',
'to' => $phone,
'type' => 'template',
'template' => array(
'name' => $templates[ $to ],
'language' => array( 'code' => 'en_US' ),
'components' => array(
array(
'type' => 'body',
'parameters' => array(
array( 'type' => 'text', 'text' => $order->get_billing_first_name() ),
array( 'type' => 'text', 'text' => $order->get_order_number() ),
),
),
),
),
);
$response = wp_remote_post(
VT_API_URL,
array(
'timeout' => 10,
'headers' => array(
'Authorization' => 'Bearer ' . VT_TOKEN, // define it in wp-config.php
'Content-Type' => 'application/json',
),
'body' => wp_json_encode( $body ),
)
);
if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
$order->add_order_note( 'WhatsApp: failed to send ' . $templates[ $to ] );
return;
}
$data = json_decode( wp_remote_retrieve_body( $response ), true );
$order->update_meta_data( $flag, $data['messages'][0]['id'] ?? 'sent' );
$order->save();
}
// Brazilian example: "(84) 99999-9999" => "5584999999999"
function vt_normalize_phone( $raw ) {
$digits = preg_replace( '/\D/', '', (string) $raw );
if ( strlen( $digits ) === 10 || strlen( $digits ) === 11 ) {
$digits = '55' . $digits; // default country code; change for your market
}
return strlen( $digits ) >= 12 ? $digits : '';
}
Before going to production:
- Keep the token out of the code. Define
VT_TOKENinwp-config.php, never in the repository. - Don’t block checkout. The call runs in the same request that changed the status. At volume, push sending to a queue.
- Store the message ID. The returned
wamidshows up in the status webhook and tells you whether the notification was delivered.
The code uses the order object’s methods (get_meta, update_meta_data, save) instead of update_post_meta, so it also works with High-Performance Order Storage (HPOS).
Path 2: WooCommerce webhooks
Go to WooCommerce > Settings > Advanced > Webhooks, click Add webhook and fill in name, status, topic, delivery URL and secret (webhooks documentation). Order topics are order.created, order.updated and order.deleted; you can also use action topics, which map to a single hook, in the form action.hook_name (REST API v3).
The payload is the same JSON the REST API would return for that order, so your backend gets status, billing.phone, number and the line items. Each delivery carries the X-WC-Webhook-Topic, X-WC-Webhook-ID, X-WC-Webhook-Delivery-ID and X-WC-Webhook-Signature headers, the last one a base64-encoded HMAC-SHA256 of the body generated with your secret. Verify it before processing:
<?php
$raw = file_get_contents( 'php://input' );
$received = $_SERVER['HTTP_X_WC_WEBHOOK_SIGNATURE'] ?? '';
$expected = base64_encode( hash_hmac( 'sha256', $raw, getenv( 'WC_WEBHOOK_SECRET' ), true ) );
if ( ! hash_equals( $expected, $received ) ) {
http_response_code( 401 );
exit;
}
$order = json_decode( $raw, true );
// $order['status'], $order['billing']['phone'], $order['number']...
http_response_code( 200 );
Things to watch:
order.updatedfires on any change, not only on status transitions. Store the last status you notified and only send when it changes.- Reply fast with a 2xx. Anything other than 2xx, 301 or 302 counts as a failure, and WooCommerce disables the webhook after more than five consecutive failures (logs under WooCommerce > Status > Logs, source
webhooks-delivery). - Initial ping. When you activate the webhook, WooCommerce pings the URL; accept it.
No backend of your own? Point the webhook to an n8n workflow.
Opt-in at checkout
Meta requires that you have the customer’s number and permission before your business starts the conversation, with your business name made clear (Get opt-in for WhatsApp). Checkout is the simplest place to capture it.
On the block-based checkout (WooCommerce 8.9 or later), use the Additional Checkout Fields API:
<?php
add_action( 'woocommerce_init', function () {
if ( ! function_exists( 'woocommerce_register_additional_checkout_field' ) ) {
return;
}
woocommerce_register_additional_checkout_field(
array(
'id' => 'my-store/whatsapp-optin',
'label' => 'Send me updates about this order from Example Store on WhatsApp',
'location' => 'order',
'type' => 'checkbox',
'required' => false,
)
);
} );
function vt_has_optin( $order ) {
$fields = \Automattic\WooCommerce\Blocks\Package::container()
->get( \Automattic\WooCommerce\Blocks\Domain\Services\CheckoutFields::class );
return (bool) $fields->get_field_from_object( 'my-store/whatsapp-optin', $order, 'other' );
}
Good practices for the field:
- Separate order updates from offers. One checkbox for order updates (utility) and another, unchecked, for offers (marketing). Agreeing to one is not agreeing to the other.
- Never pre-check it. Consent must be the customer’s own action.
- Keep proof. Also record the date and the exact text accepted.
On the classic (shortcode) checkout, the field is added through the checkout form hooks, not this API. Our WhatsApp opt-in list guide has sample wording. If you sell to Brazil, the LGPD (Law 13,709/2018, Brazil’s data protection law) applies to this data; this article is not legal advice.
Pending payments: bank transfer, Pix and boleto
Orders created but not paid need their own flow. In Brazil this is mostly Pix codes that expire and boletos with a due date:
- The order enters
pendingoron-hold(depending on the gateway). Immediately send the template with the amount and deadline. - Schedule a check close to the expiry date. If the order is still in the same status, send a reminder.
- When the status moves to
processing, cancel pending reminders and send the payment confirmation.
Keep the text strictly about the order so Meta approves it as utility. Discounts, urgency (“hurry, stock is running out”) or product suggestions turn the template into marketing, according to the template categorization guidelines. An abandoned cart, where no order exists yet, is always marketing and requires marketing opt-in. Our guide to recovering Pix, boleto and abandoned carts covers timing, copy and the template with a payment button.
Templates by event and cost
| Event | Sample body | Category | Meta cost (Brazil) |
|---|---|---|---|
| Order created, awaiting Pix | “Hi {{1}}. Your order {{2}} is awaiting Pix payment until {{3}}.” | Utility | R$ 0.0350 |
| Payment received | “{{1}}, payment for order {{2}} has been confirmed.” | Utility | R$ 0.0350 |
| Order shipped | “Your order {{1}} has shipped. Tracking code: {{2}}.” | Utility | R$ 0.0350 |
| Abandoned cart | “You left {{1}} in your cart.” | Marketing | R$ 0.3217 |
Prices per delivered message for recipients in Brazil, in Brazilian reais (R$), since October 1, 2026 (Meta pricing); rates differ by recipient country. Since that date, utility templates sent inside the customer service window are also charged, and the free tier of 1,000 messages per number per month applies only to service messages. More ready-to-use examples in WhatsApp template examples and the category rules in how Meta categorizes your template.
How to do it with Vectalk
Vectalk is a proxy for Meta’s official WhatsApp Cloud API. The flow for a WooCommerce store:
- Create your account and connect your number; with coexistence, it stays on the WhatsApp Business app too.
- Create the templates in the dashboard (there is a Template Library) and wait for approval.
- Use the instance API key in the code above, which calls
POST https://apis.vectalk.com.br/api/messages(send template). - Configure the instance webhook to receive statuses and replies.
- Top up your balance: each delivered message is deducted from your prepaid balance, with no card registered at Meta.
Vectalk has no inbox or bulk sending in its dashboard: customer replies reach your own system or the support tool you already use through the webhook.
Frequently asked questions
Do I need a plugin to connect WooCommerce and WhatsApp?
No. A few lines of PHP on a hook, or a native WooCommerce webhook calling the official API, is enough.
Which phone number does WooCommerce use?
The billing phone field (billing.phone). It is free text, so normalize it to international format with digits only (country code + area code + number) before sending.
Can I send the tracking code on WhatsApp?
Yes, as a utility template with the code as a variable. Take the code from your shipping plugin or from wherever the store records it and pass it as a template parameter.
My WooCommerce webhook stopped arriving. What happened?
Most likely it was disabled after more than five consecutive failures. Check its status under Settings > Advanced > Webhooks, look at the webhooks-delivery log, fix the endpoint and re-enable it.
Official sources consulted on October 29, 2026: WooCommerce: WC_Order class (status hooks) · WooCommerce: Webhooks · WooCommerce REST API v3: Webhooks · WooCommerce: Additional checkout fields · Meta: Get opt-in for WhatsApp · Meta: Template categorization · Meta: Pricing · Vectalk: Send template
Put your business on the official WhatsApp
Create your account, connect your number to the official API (you can keep the app with coexistence) and start serving customers and sending messages.
