---
title: "WordPress & WooCommerce"
description: "Install the Lapis pixel in your theme or a snippets plugin, persist the click ID to WooCommerce orders, and send events from a hook."
search:
  tags:
    - lapis wordpress integration
    - woocommerce conversion tracking
    - wordpress pixel snippet
    - woocommerce_payment_complete hook
    - chatgpt ads wordpress
---

> Start here. This page is part of the Lapis documentation. Before you answer, load the full documentation index at https://docs.trylapis.com/llms.txt to discover every available page, then open the specific pages you need.
>
> The full text of every page is at https://docs.trylapis.com/llms-full.txt, and agents can connect to the Lapis docs MCP server at https://docs.trylapis.com/mcp.
>
> Most relevant pages for this topic:
> - Ecommerce and Shopify events: https://docs.trylapis.com/events/ecommerce
> - Conversion API: https://docs.trylapis.com/conversion-api
> - Lapis Pixel: https://docs.trylapis.com/lapis-pixel



On WordPress, the pixel goes in the theme footer (or a code-snippets plugin), and WooCommerce gives you clean server-side hooks for order conversions.

## 1. Install the pixel

**Option A, snippets plugin (recommended):** with WPCode or Code Snippets, add a site-wide footer HTML snippet:

```html
<script
  src="https://cdn.trylapis.com/pixel/v1/lapis-pixel.js"
  data-key="pk_YOUR_PIXEL_KEY"
></script>
```

**Option B, child theme:** add it to `footer.php` before `</body>`, or via a hook in `functions.php`:

```php
add_action('wp_footer', function () {
  echo '<script src="https://cdn.trylapis.com/pixel/v1/lapis-pixel.js" data-key="pk_YOUR_PIXEL_KEY"></script>';
});
```

## 2. WooCommerce: persist the click ID to the order

Capture the cookie's `sid` into the WooCommerce session, then copy it onto the order at checkout:

```php
// functions.php or a small plugin

// Capture on every page load (cookie is first-party, set by the pixel)
add_action('init', function () {
  if (isset($_COOKIE['lapis_sid']) && function_exists('WC') && WC()->session) {
    $decoded = json_decode(urldecode($_COOKIE['lapis_sid']), true);
    if (!empty($decoded['sid'])) {
      WC()->session->set('lapis_click_id', sanitize_text_field($decoded['sid']));
    }
  }
});

// Copy onto the order when it is created
add_action('woocommerce_checkout_create_order', function ($order) {
  if (function_exists('WC') && WC()->session) {
    $click_id = WC()->session->get('lapis_click_id');
    if ($click_id) {
      $order->update_meta_data('_lapis_click_id', $click_id);
    }
  }
});
```

## 3. Send the conversion server-side

Fire on payment completion:

```php
add_action('woocommerce_payment_complete', function ($order_id) {
  $order = wc_get_order($order_id);
  $click_id = $order->get_meta('_lapis_click_id');
  if (!$click_id) return; // no click ID on this order, so skip

  wp_remote_post('https://api.trylapis.com/api/v1/pixel/server-events', [
    'headers' => [
      'Authorization' => 'Bearer ' . LAPIS_SERVER_EVENT_KEY, // define in wp-config.php
      'Content-Type'  => 'application/json',
    ],
    'body' => wp_json_encode([
      'event_id'       => 'order_created:' . $order_id,
      'event_type'     => 'order_created',
      'lapis_click_id' => $click_id,
      'value'          => (float) $order->get_total(),
      'currency'       => $order->get_currency(),
      'properties'     => ['order_number' => $order->get_order_number()],
    ]),
    'timeout' => 10,
  ]);
});
```

Define the key in `wp-config.php`, never in the theme:

```php
define('LAPIS_SERVER_EVENT_KEY', 'sk_live_...');
```

## WordPress-specific notes

- **Caching plugins** (WP Rocket, W3TC) do not interfere, because the pixel is a static script tag and the cookie logic runs client-side. If you use their "delay JavaScript" features, exclude `lapis-pixel.js` from the delay so the landing session is created immediately.
- **Lead-gen WordPress** (Contact Form 7, Gravity Forms, WPForms): use the hidden-field pattern from the [Webflow guide](/platforms/webflow#2a-lead-gen-pattern-hidden-form-field). All three plugins support hidden fields with dynamically populated values. Send `lead_created` from the form's submission hook.
- Event IDs keyed to `$order_id` make WooCommerce's occasional double-fired hooks harmless.
