Skip to content

Connect WooCommerce

Connecting WooCommerce sends purchases and refunds into Klarvyn as they happen — no plugin to install and no keys to copy. Add the small checkout snippet below and every purchase is attributed back to the campaign that produced it.

  1. Log into your WordPress admin (wp-admin) first — WooCommerce’s approval screen requires an active session.

  2. In Klarvyn, go to Settings → Integrations, open the WooCommerce card and enter your Store URL (must be HTTPS, and the exact address where WooCommerce lives — subdomain or subdirectory included).

  3. Click Connect Store and approve the connection on your store’s page. Klarvyn receives the API credentials directly from WooCommerce and registers the order webhooks automatically.

  4. Place a test order and move it to processing — it appears in Contacts → Purchases within seconds.

  • Purchases when an order reaches processing or completed — revenue, currency, products and line items. No double-counting when an order passes through both statuses.
  • Refunds — partial and full — recorded as negative revenue.
  • Customers become contacts, matched by billing email (with phone as fallback), enriched with name and location.

WooCommerce orders don’t carry ad or UTM data of their own, so make sure the Klarvyn tracking script runs on your store. With it in place, purchases are attributed in two tiers:

  1. Automatic fallback — Klarvyn looks up the buyer’s recent tracked visits (last 30 minutes before the order, matched to that specific visitor or contact) and copies the UTMs and click IDs onto the purchase. This needs no extra setup, but only covers purchases made shortly after a tracked visit.

  2. Exact matching (recommended) — add the snippet below to your store. Because WooCommerce checkout runs on your own domain, the tracker’s first-party visitor cookie is available at checkout; the snippet copies it into the order, and Klarvyn stitches the purchase to the visitor’s full journey — first touch included — no matter how long ago the ad click happened.

Add this with the free Code Snippets plugin, or in your child theme’s functions.php:

/**
* Klarvyn — carry the visitor id into WooCommerce orders for ad attribution.
* Requires the Klarvyn tracking script to be installed on this site.
*/
function klarvyn_order_attribution_meta( $order ) {
foreach ( array( 'kv_vid' => '_kv_vid', 'kv_sid' => '_kv_sid' ) as $meta_key => $cookie ) {
if ( ! empty( $_COOKIE[ $cookie ] ) ) {
$value = sanitize_text_field( wp_unslash( $_COOKIE[ $cookie ] ) );
if ( preg_match( '/^[A-Za-z0-9_-]{1,64}$/', $value ) ) {
$order->update_meta_data( $meta_key, $value );
}
}
}
}
// Classic (shortcode) checkout.
add_action( 'woocommerce_checkout_create_order', 'klarvyn_order_attribution_meta' );
// Block-based checkout (the WooCommerce default since 8.3).
add_action( 'woocommerce_store_api_checkout_update_order_meta', 'klarvyn_order_attribution_meta' );

The snippet handles both the classic shortcode checkout and the block-based checkout, and writes two order meta fields: kv_vid (the visitor) and kv_sid (the session). It only ever reads Klarvyn’s own first-party cookies, which exist only for visitors who granted analytics consent — so it is safe alongside your cookie banner.

To verify it works: visit your store in a fresh browser (accept cookies), place a test order, then open the order in WooCommerce → Orders and check the Custom Fields section for kv_vid — or simply check that the purchase in Klarvyn shows the visitor’s traffic source.

  • Without the tracking script, purchases still flow in and match contacts by billing email — there is just no visitor journey to attribute them to.
  • One store per workspace — connecting a second store replaces the first.
  • Subscriptions aren’t captured from WooCommerce Subscriptions — use your payment processor’s integration (e.g. Stripe) for recurring revenue.
  • Disconnect removes the Klarvyn webhooks from your store; the API key entry stays visible in WooCommerce’s own REST API list and can be deleted there. Recorded data is kept.