WooCommerce is the easier of the two big storefronts to instrument server-side, and the reason is structural: it runs on your own server, so an order-status hook fires where you can reach it. That single fact removes most of the constraints Shopify imposes.
Why WooCommerce is the simpler case
On WooCommerce, the checkout is your code. The order status is your database row. That means:
- you can add a hook on status change and post it anywhere
- you are not limited to a sandboxed browser surface
- the purchase signal can come from the server at the moment the order is genuinely confirmed
For a COD store this is not a convenience, it is the only clean path.
The three pieces
1. The container and one CNAME
Create the container, paste your GTM server container config, then point a subdomain CNAME at connect.bonicbd.com. Certificate issues once it resolves.
2. The snippets
The WooCommerce plugin places the GTM loader and the tracker in the right positions, which matters more than it sounds — a tracker loaded after your theme's scripts captures click IDs after something else may have already rewritten the URL.
If you install by hand instead, both go in <head>, above everything else.
3. The order hook
This is the piece that does the real work on a COD store. On status change to a confirming status, post to the COD webhook with the order id, value, currency and hashed customer data.
The dataLayer events WooCommerce already gives you
WooCommerce and its GTM integrations push a usable set of events. The ones worth wiring:
| Event | Fires on | What to check |
|---|---|---|
view_item |
product page | item_id matches your SKU, not the variation id |
add_to_cart |
cart addition | value is the unit price, not the line total |
begin_checkout |
checkout page load | fires once, not on every AJAX refresh |
purchase |
thank-you page | should not be your purchase source on a COD store |
That last row is the one to act on. On a COD store the thank-you-page purchase should be retired in favour of the confirmation hook.
Plugin conflicts, the real risk
A typical Bangladesh WooCommerce store runs a pixel plugin, a CAPI plugin, a page builder and a GTM integration at once. Three of them will each try to fire a purchase.
Signs you have this:
- Meta shows more purchases than orders in WooCommerce
- the thank-you page fires two
purchaseevents in the dataLayer - an order has two different
event_idvalues in Events Manager
The fix is not another plugin. Turn off every purchase emitter except the one you intend to keep, then verify with a real order.
Step by step
- Create the container, add the CNAME
- Install the plugin, confirm the snippets load above theme scripts
- Disable purchase tracking in any pixel or CAPI plugin
- Configure destinations in the container
- Wire the order-status hook for the purchase
- Place a test order, confirm it, follow it in the dashboard
- Compare Meta's count against the WooCommerce order list for a week
The PHP hook, concretely
The order-status hook is the one piece that may need a developer, so here is the shape of it.
WooCommerce fires woocommerce_order_status_changed with the order id and both the old and new status. You want to act only when the new status is one that means the sale is going ahead.
add_action('woocommerce_order_status_changed', function ($order_id, $from, $to) {
// confirm-list only; anything else is ignored upstream too
$confirm = ['processing','completed','shipped','delivered'];
if (!in_array($to, $confirm, true)) return;
$order = wc_get_order($order_id);
if (!$order) return;
$payload = [
'order_id' => 'WC-' . $order_id,
'value' => (float) $order->get_total(),
'currency' => $order->get_currency(),
'type' => 'order.status',
'status' => $to,
];
wp_remote_post('https://track.yourdomain.com/c/<cid>/cod/webhook', [
'timeout' => 8,
'headers' => [
'Content-Type' => 'application/json',
'x-bonicbd-webhook-secret' => '<secret from panel>',
'x-bbd-request-id' => 'wc-' . $order_id . '-' . $to,
'x-bbd-timestamp' => (string) time(),
],
'body' => wp_json_encode($payload),
]);
}, 10, 3);
Three details that matter in that snippet:
- the request id is derived from order and status, so a retried hook call returns the stored response instead of creating a second event
- the timestamp is current, because the endpoint rejects a request outside its replay window
- the secret is a header, never a query parameter — a credential in a query string is refused
What happens if the hook fires twice
WooCommerce can fire a status change more than once in a single request — a bulk status update, a plugin that re-saves the order, or a retry after a timeout. This is normal and it is why idempotency exists.
With a stable request id, the second call returns the first response. Without one, the second call is a new attempt, and if it produces a second event you will see two purchases for one order.
Handling refunds and returns
WooCommerce has refunded and cancelled statuses, and they matter for reporting honesty. A cancelled order should close without a purchase; a refunded order should send an adjustment so the platform stops counting revenue you gave back.
For a return that left the warehouse and came back, the payload needs a separate return id. Without one, the refund event collides with the original purchase.
A verification checklist that catches the real failures
- place a ৳10 test order, confirm it, and watch the dashboard move it from held to sent
- change the status to cancelled on a second test order and confirm no purchase is sent
- deactivate the plugin and confirm tracking stops (this is how you know the plugin is what was doing the work)
- switch theme on a staging copy and confirm the snippets are gone — then document that they must be re-added
That fourth check sounds pessimistic. It is the one that saves the most money.
Frequently asked questions
Do I need a developer?
No, if you can paste snippets into a theme or plugin settings and add a CNAME at your domain provider. The order hook is the one piece that may need someone comfortable writing a small PHP snippet.
Where does the order hook go?
A small plugin or a child-theme functions.php. Add a handler on woocommerce_order_status_changed that posts the order id, value and currency to your COD webhook endpoint (https://track.yourdomain.com/c/<cid>/cod/webhook) with the webhook secret in a header. Customer identifiers are hashed by the tracker on the browser side — the hook itself only needs order data.
Does this work on shared hosting?
Yes. BonicBD's container is hosted, so your store only makes an outbound HTTPS request. No additional server capacity is needed.
Will it slow the site down?
The snippets are small and deferred, and forwarding happens on our infrastructure rather than your PHP process — but asynchronous scripts still use network and CPU. Measure your own pages before and after; the net effect depends on your theme, scripts and payload size.
What about HPOS (High-Performance Order Storage)?
WooCommerce's newer order storage changes where order data lives, not whether the status hook fires. Both storages work, but check your plugin's compatibility before switching.
Can I run it next to my existing pixel?
Yes, and you should for a week — compare the numbers, then retire the browser-side purchase. Running both without a shared identifier is how duplicate purchases appear.
Read next
- Shopify setup for the other platform's constraints
- Shopify vs WooCommerce if you are still choosing
- COD Order Tracking for the confirmation path in full
Related in this cluster
- cod order tracking — the cluster hub, start here
- shopify vs woocommerce tracking
- shopify woocommerce tracking bangla
- server side gtm keno dorkar
Practical next steps: COD order tracking · how the event path works · plans in BDT
Compare the BonicBD feature set, review the setup guide, or contact the team if you want help with a live server-side GTM rollout.