> ## Documentation Index
> Fetch the complete documentation index at: https://docs.partnero.com/llms.txt
> Use this file to discover all available pages before exploring further.

# WooCommerce integration

> Track orders from your WooCommerce store

## Overview

Connect your WooCommerce store to automatically track orders and attribute sales to partners.

## Features

* **Automatic order tracking** - Orders create transactions automatically
* **Coupon integration** - Partner coupons track referrals
* **Customer syncing** - WooCommerce customers synced to Partnero
* **Subscription support** - Works with WooCommerce Subscriptions

## Setup

### Step 1: Install Plugin

Install the Partnero plugin in WordPress:

1. Go to **Plugins → Add New** in WordPress admin
2. Search for "Partnero"
3. Click **Install Now** and then **Activate**

Or download from [partnero.com/integrations/woocommerce](https://partnero.com/integrations/woocommerce).

### Step 2: Connect to Partnero

1. Go to **WooCommerce → Settings → Partnero**
2. Enter your Partnero API key
3. Select your program
4. Click **Connect**

### Step 3: Configure Settings

Configure tracking options:

| Setting              | Description                        |
| -------------------- | ---------------------------------- |
| **Track All Orders** | Create transactions for all orders |
| **Sync Customers**   | Sync customer data to Partnero     |
| **Cookie Duration**  | How long referral cookies last     |

## How It Works

### Order Tracking Flow

```mermaid theme={null}
flowchart LR
    A[Customer Places Order] --> B[Order Completed]
    B --> C[Plugin Sends Data]
    C --> D[Transaction Created]
    D --> E[Commission Calculated]
```

### Attribution Methods

Orders are attributed via:

1. **Referral Cookie** - Customer clicked referral link before ordering
2. **Coupon Code** - Customer used partner's coupon at checkout
3. **Customer Match** - Existing customer linked to partner

## Coupon Integration

### Creating Partner Coupons

Partners can have unique coupon codes:

1. Create coupon in WooCommerce
2. Link coupon to partner in Partnero
3. When used, order is attributed to partner

### Automatic Coupon Sync

Enable automatic coupon creation:

1. Go to **WooCommerce → Settings → Partnero → Coupons**
2. Enable **Auto-create partner coupons**
3. Configure discount amount and type

## Subscription Support

If using WooCommerce Subscriptions:

### Initial Purchase

First subscription payment creates transaction with commission.

### Renewals

Each renewal payment:

* Creates new transaction
* Calculates commission (if recurring enabled)
* Updates partner's balance

### Subscription Management

Handled events:

* `woocommerce_subscription_renewal_payment_complete`
* `woocommerce_subscription_status_changed`

## Tracking Script

The plugin automatically adds tracking to your store:

```html theme={null}
<!-- Added automatically by plugin (PartneroJS) -->
<script>
  (function(p,t,n,e,r,o){...})(window, document, 'script', 'https://app.partnero.com/js/universal.js', 'po');
  po('settings', 'assets_host', 'https://assets.partnero.com');
  po('program', 'YOUR_PROGRAM_ID', 'load');
</script>
```

## Manual Installation

If not using the plugin, add tracking manually:

### Add to Theme

Add to your theme's `header.php` or via a custom plugin:

```php theme={null}
add_action('wp_head', function() {
    ?>
    <!-- PartneroJS -->
    <script>
      (function(p,t,n,e,r,o){ p['__partnerObject']=r;function f(){
      var c={ a:arguments,q:[]};var r=this.push(c);return "number"!=typeof r?r:f.bind(c.q);}
      f.q=f.q||[];p[r]=p[r]||f.bind(f.q);p[r].q=p[r].q||f.q;o=t.createElement(n);
      var _=t.getElementsByTagName(n)[0];o.async=1;o.src=e+'?v'+(~~(new Date().getTime()/1e6));
      _.parentNode.insertBefore(o,_);})(window, document, 'script', 'https://app.partnero.com/js/universal.js', 'po');
      po('settings', 'assets_host', 'https://assets.partnero.com');
      po('program', '<?php echo PARTNERO_PROGRAM_ID; ?>', 'load');
    </script>
    <!-- End PartneroJS -->
    <?php
});
```

### Track Orders via Webhook

Set up WooCommerce webhook:

1. Go to **WooCommerce → Settings → Advanced → Webhooks**
2. Add webhook with URL: `https://api.partnero.com/v1/integrations/woocommerce/{program_id}/webhook`
3. Select topic: **Order created**

## Customer Sync

Sync WooCommerce customers to Partnero:

```bash theme={null}
# API endpoint for WooCommerce sync
curl -X POST https://api.partnero.com/v1/customers/woocommerce/sync \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "customer_id": 123,
    "email": "customer@partnero.com",
    "name": "John Doe",
    "woocommerce_id": "wc_456"
  }'
```

## Testing

### Test Orders

Create test orders to verify integration:

1. Enable WooCommerce test mode
2. Place test order with referral cookie set
3. Verify transaction appears in Partnero

### Debug Mode

Enable debug logging:

1. Go to **WooCommerce → Settings → Partnero → Debug**
2. Enable debug mode
3. Check logs in **WooCommerce → Status → Logs**

## Troubleshooting

<AccordionGroup>
  <Accordion title="Orders not tracked">
    * Verify plugin is activated
    * Check API key is correct
    * Ensure webhook is configured
  </Accordion>

  <Accordion title="Partner not attributed">
    * Verify referral cookie is set
    * Check coupon code is linked
    * Test with debug mode enabled
  </Accordion>

  <Accordion title="Plugin conflicts">
    * Disable other plugins to test
    * Check JavaScript console for errors
    * Update to latest plugin version
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Commissions" icon="percent" href="/guides/rewards/commissions">
    Configure product commissions
  </Card>

  <Card title="Coupons" icon="tag" href="/api-reference/coupons/list">
    Manage partner coupons
  </Card>
</CardGroup>
