WooCommerce Integration

Track affiliate conversions on WooCommerce stores via native WC events, DOM scraping, or dataLayer — with a manual PHP fallback for fully custom themes.

Overview

The SDK's WooCommerce integration supports three tracking methods, tried in order:

  • Native WC event — listens for wc-blocks_checkout_complete or the legacy woocommerce_checkout_order_processed JS event
  • DOM scraping — reads order number, total, and currency from the .woocommerce-order-details table on the thank-you page
  • dataLayer push — listens for the purchase event via Google Tag Manager enhanced e-commerce schema

Installation

Add the snippet to your theme's footer.php, or enqueue it via a plugin. The snippet must load on all pages to capture the initial click.

01

Add to footer.php

Navigate to Appearance → Theme File Editor → footer.php and paste before </body>.

02

Or: enqueue via functions.php

Use wp_enqueue_script if you prefer not to edit template files directly.

HTML (footer.php)
<script src="https://assets.affclix.com/sdk/v3/affclix-sdk.min.js"></script>
<script>
  AffclixSDK.init({
    trackingDomain: 't.yourdomain.com',
    cookieDomain:   '.yourdomain.com'
  });

  // Auto-detects the order-received / thank-you page, listens for the
  // wc:order_received DOM event, and polls DataLayer for purchase events.
  AffclixSDK.integrations.woocommerce.init({
    campaignID: 'YOUR_CAMPAIGN_ID',
    autoTrack:  true
  });
</script>

How It Works

01

Click Capture

On every page load the SDK reads UTM params and utk_click_id from the URL and stores them in a first-party cookie.

02

Thank-You Page Detection

The SDK detects the is-woocommerce-order-received body class or wc_order_received JS global to identify the confirmation page.

03

Order Data Extraction

Tries native WC event → DOM scrape → dataLayer, in that order. First successful source wins.

04

Postback Fired

Normalised order payload is sent to your Affclix endpoint. Duplicate order IDs are suppressed server-side for 24 h.

Manual Tracking

For custom themes where auto-detection fails, output order data directly via PHP and pass it to the SDK.

Tracked Fields

FieldSourceDescription
orderIdget_order_number()Used for deduplication — never credited twice
revenueget_total()Order total including tax, excluding shipping by default
currencyget_woocommerce_currency()Store base currency (ISO 4217)
couponget_coupon_codes()Comma-separated discount codes applied
utk_click_idCookie / localStorageAffclix click attribution ID set on landing
utm_sourceCookie / localStorageCaptured on first touch

Troubleshooting

Conversion not firing

Enable debug: true in AffclixSDK.init() and open the browser console on the thank-you page. Look for [Affclix] WooCommerce — order detected.

WooCommerce Blocks (Gutenberg Checkout)

If your store uses the WooCommerce Blocks checkout, the legacy woocommerce_checkout_order_processed JS event is NOT fired. The SDK covers this by detecting the order-received / thank-you page directly and by polling dataLayer for purchase events — ensure you are on SDK v3 or later.

Double conversions

Check that you are not calling AffclixSDK.integrations.woocommerce.init() more than once per page. The SDK guards against duplicate order tracking client-side (per txn_id, 30-day window), but duplicate init calls waste bandwidth.

Rate this article
★★★★★
Thanks for rating!

Was this article helpful?