WooCommerce

There are two ways to connect WooCommerce. The server connector (recommended) syncs your product catalog and receives orders automatically over WooCommerce's REST API: no theme edits. The snippet is the fallback when you can't create REST API keys.

The connector reads your catalog straight from WooCommerce. It also receives webhooks: automatic updates WooCommerce sends the moment an order or a product changes. Your products and orders stay in sync, with no code on your storefront.

1

Create a REST API key

In WordPress admin, go to WooCommerce → Settings → Advanced → REST API and click Add key. Give it Read/Write permission and copy the Consumer key and Consumer secret (the secret is shown only once).

2

Connect in A vs B

In A vs B, open Commerce → Sources, choose WooCommerce, and paste your Store URL (for example https://store.example.com), Consumer key, and Consumer secret. We verify the credentials, register order and product webhooks, and start a full catalog import. If a field is missing or not valid, the reason appears under that field.

What syncs automatically once connected:

  • Catalog: titles, prices, availability, and variants (different versions of a product, like size or color), refreshed on every product change.
  • Orders: new orders and updates (including refunds) arrive as webhooks and appear in your orders summary.
Profit metrics need a cost field

WooCommerce has no native per-variant cost field, so profit and margin metrics are not available for WooCommerce stores. Revenue, RPV, and conversion metrics work fully.

Attribution still comes from the snippet: install it (below) so orders can be linked to the A vs B visitor who placed them. Orders the connector receives without a visitor link are counted as unattributed: they show in your orders totals but not in experiment results.

Snippet fallback

If you can't create REST API keys, install the snippet and record purchases with a theme hook instead.

Your snippet comes from Project Settings → Snippet in the A vs B dashboard:

HTML
<script>window.avsb=window.avsb||{};window.avsb.q=window.avsb.q||[];window.avsb.ready=window.avsb.ready||function(f){window.avsb.q.push(f)};window.avsb.on=window.avsb.on||function(n,f){var t=['on',n,f];window.avsb.q.push(t);return function(){t[0]=null}};window.avsb.consent=window.avsb.consent||{set:function(s){window.avsb.q.push(['consent.set',s])},get:function(){return{}}};window.avsb.track=window.avsb.track||{};['event','segment','purchase','cart'].forEach(function(m){window.avsb.track[m]=window.avsb.track[m]||function(a,b){window.avsb.q.push(['track.'+m,a,b])}});(function(){window.avsb._t0=Date.now();window.avsb._df=fetch('https://cdn.avsb.cloud/YOUR_SNIPPET_KEY/datafile.json').catch(function(){});var d=document,e=d.documentElement,s=d.currentScript,a=s&&s.getAttribute('data-avsb-timeout'),t=a==null?3000:+a;if(!(t>0)||window.avsb.version)return;e.style.opacity='0';e.style.pointerEvents='none';window.avsb._t=setTimeout(function(){e.style.removeProperty('opacity');e.style.removeProperty('pointer-events')},t)})();</script><script src="https://cdn.avsb.cloud/snippet.js?id=YOUR_SNIPPET_KEY" data-avsb="YOUR_SNIPPET_KEY" async></script>
HTML9 lines

The easiest path is a header plugin: see the WordPress guide. If you prefer code, add both tags to your child theme's functions.php with the wp_head action at priority 1.

Then record purchases on the order-received page. If your store already pushes a GA4 purchase event to window.dataLayer (for example via GTM4WP), and your product catalog is connected, turn on Google Analytics 4 / dataLayer on your project's Product catalog page and you're done. Otherwise add the woocommerce_thankyou hook:

PHP
add_action('woocommerce_thankyou', function ($order_id) {  $order = wc_get_order($order_id);  if (!$order) {    return;  }  ?>  <script>    avsb.ready(function () {      avsb.track.purchase({        orderId: '<?php echo esc_js($order->get_order_number()); ?>',        total: <?php echo (float) $order->get_total(); ?>,        currency: '<?php echo esc_js($order->get_currency()); ?>',        shipping: <?php echo (float) $order->get_shipping_total(); ?>,        tax: <?php echo (float) $order->get_total_tax(); ?>,        discount: <?php echo (float) $order->get_discount_total(); ?>      });    });  </script>  <?php});
PHP20 lines

Orders are deduplicated by orderId (last write wins), so a buyer refreshing the page never double-counts, and running the hook alongside the server connector is safe.

Use a child theme or a snippets plugin

Edits to a parent theme's functions.php are wiped by theme updates. Put the hook in a child theme or a code-snippets plugin so it survives updates.

Verify

Place a test order, then open Commerce → Orders in the A vs B dashboard. See the orders & attribution guide for how to read it: it shows recent orders, totals by currency, and any orders that couldn't be attributed to an experiment exposure. An exposure is the moment a visitor actually saw the test.

Was this helpful?