# WooCommerce

> Install our free plugin and paste in your connect code – clicks and sales are tracked from your own server.

On WooCommerce you use our plugin, **Affilyflow – Affiliate Tracking**. It remembers the affiliate click and reports the order from your own server, so an ad blocker can't swallow it. You don't touch your theme and you don't write any code.

## Before you start

- WordPress with WooCommerce activated, and a user who is allowed to install plugins.
- Your connect code. You'll find it under **Program → Setup** once you have chosen **WooCommerce**.
- The site must be public – if your WordPress site is set to private, neither we nor your customers can reach it.

## 1. Install and connect the plugin

1. Download the plugin from [store.affilyflow.com/downloads/affilyflow-woocommerce.zip](https://store.affilyflow.com/downloads/affilyflow-woocommerce.zip). It's free.
2. In WordPress, go to **Plugins → Add New Plugin → Upload Plugin**, choose the zip file, install it and activate the plugin.
3. Open the Affilyflow page. The quickest way is the **Forbind** (Connect) link next to the plugin in the plugins list, right beside the link that deactivates it. (Once the plugin is connected, the link reads **Indstillinger** – Settings.)
4. Paste the connect code into the field and press **Forbind** (Connect).

That's it. Sales from your affiliates are counted automatically.

> [!TIP]
> Can't find **Upload Plugin**? The button sits at the top of the **Add Plugins** page, to the right of the heading. Can't see the link to the Affilyflow page? It is also under **WooCommerce → Affilyflow** – or **Settings → Affilyflow** if WooCommerce isn't activated. Some hosted WordPress set-ups hide third-party menu items; then the link in the plugins list is the only way in.

The plugin's own settings page is in Danish. This guide gives the Danish labels in bold with the English meaning in brackets.

## 2. Confirm the connection

Step 3 in Setup is called **Confirm** and has two rows:

- **The plugin connection.** Press **Test the plugin connection**. The self-test asks the plugin to call us (about 10 seconds) and shows whether it was recognised as your store and which version you are running.
- **A full sale.** Optional and free: press **Open test link** and place a test order in the same browser. The live test shows the click, the order number and the amount all the way through.

The self-test proves that the plugin can reach us. Whether orders are reported is only shown by a sale – the first real sale confirms itself, so the test purchase isn't required. If the self-test fails, the causes are listed in [Testing and troubleshooting](https://www.affilyflow.com/en/docs/store/testing-and-troubleshooting#woocommerce-the-self-test).

## What the plugin does

- **The click.** When a customer lands with `?afid=` from an affiliate link, the plugin stores the click ID in a cookie set by your own server for 90 days. The program's own cookie period is enforced on our server.
- **The sale.** The order is reported once it is paid or reaches the status *processing* or *completed* in WooCommerce.
- **The commission base.** Commission is calculated on the value of the goods: the order lines after discounts, excluding VAT and shipping. Payment and handling fees are not included; discounts given as a negative fee are deducted.
- **Line items** are sent along, so you and your affiliates can see which products sell.
- **Self-referral.** If an affiliate buys through their own link with the same email address as their account, the sale is recorded as rejected. It costs you nothing.
- **Heartbeat.** From version 1.9.0 the plugin checks in once a day, so we can tell a quiet store from a lost connection.
- **Coverage.** From version 1.11.0 the plugin reports when a customer lands with an affiliate click and when the click has been stored – only the click ID and your store. That lets **Tracking coverage** in Setup show where clicks go missing.
- **Delivery with retries.** From version 1.12.0 sales, refunds and cancellations are sent from WooCommerce's own queue (Action Scheduler), outside the customer's request, and the reply is read. If a call fails (a network error, a brief server error), it is retried after 1 min, 5 min, 30 min, 2 h, 12 h and 24 h. The outcome is written as an order note on the order and shown as **Seneste ordre meldt** (last order reported) on the Affilyflow page in WordPress.
- **Consent.** From version 1.12.0: if you use a cookie banner that supports the WP Consent API (Complianz, Cookiebot, CookieYes and others), the click is only stored once the customer has accepted marketing. Until then the click ID is kept in memory on the page and stored the moment consent is given. Without such a banner the click is stored straight away.
- **Express and embedded checkouts.** From version 1.12.0 the click is also captured on orders placed with PayPal, Apple Pay and Google Pay buttons and with embedded payment solutions (Klarna, Nets) – and never on orders an administrator creates in wp-admin.
- **Safari.** From version 1.12.0 the plugin sets `af_t` and `af_srv` alongside `af_click`. If you also run our script on the site, it keeps the server's cookie for the full period instead of a JavaScript cookie, which Safari cuts to about 7 days.
- **Subscriptions.** From version 1.12.0 renewal orders from WooCommerce Subscriptions are not reported as new sales (commission on renewals is currently only available through Stripe).
- **Updates.** Automatic updates are switched on the first time the plugin is activated. You can turn them off in the plugins list.

## Refunds and cancellations

A full refund, or a cancelled or failed order, rejects the sale: no commission and no fee, and the affiliate is notified.

From version 1.10.0 a partial refund reduces commission and fee in proportion:

- If you refund specific products, the commission is reduced by exactly those products, excluding VAT.
- A refund of shipping only does not change the commission.
- A refund of an amount without products reduces the commission by the same share of the order.
- If the program pays a fixed amount per sale, a partial refund does not change it.

Once the refunds together cover the whole order, the sale is rejected.

## Personal discount codes

From version 1.11.0 a [personal discount code](https://www.affilyflow.com/en/docs/store/personal-discount-codes) earns commission, even without a click. With automatic updates switched on, you get the version by itself. Create the code in WooCommerce and under **Program → Discount codes** in Affilyflow, and choose the affiliate under **Who is the code for?**. The rest happens on its own:

- An order without an affiliate click is only reported when it was placed with a personal code. Before anything is sent, the plugin compares the customer's codes with a list of one-way fingerprints of your personal codes. Orders with general codes, or with no code at all, never leave your store.
- An order with a click carries its discount codes along, so a personal code can still credit the sale if the click has expired.
- A valid click always beats a code. With **Sidste klik vinder** (last click wins) switched on, another network's latest click also beats a personal code, so you never pay two networks for the same sale.
- Refunds and cancellations work as they do for sales with a click.

## Last click wins

If you also work with other affiliate networks, the latest affiliate click counts across networks (from version 1.10.0, on by default). If the customer comes back through another network's link after an Affilyflow click, the plugin forgets our click and the order is not reported to us. If the customer then clicks an Affilyflow link again, the sale is ours again.

The plugin recognises Partner-Ads, Tradedoubler (including Grow), Adtraction, Awin, impact.com, CJ, Rakuten, Admitad and links tagged `utm_medium=affiliate`. The setting is called **Sidste klik vinder** (last click wins) on the Affilyflow page in WordPress.

The plugin only decides for Affilyflow. If the other networks' pixels should follow the same rule, you can make them conditional on the winner, which is stored in the cookie `afw_last_network` and returned by the PHP function `affilyflow_last_network( $order )`:

```php title="functions.php · example"
add_action( 'woocommerce_thankyou', function ( $order_id ) {
    $network = function_exists( 'affilyflow_last_network' ) ? affilyflow_last_network( $order_id ) : '';
    if ( in_array( $network, array( '', 'partner-ads' ), true ) ) {
        // Partner-Ads' salgspixel her
    }
    if ( in_array( $network, array( '', 'tradedoubler' ), true ) ) {
        // Tradedoublers konverteringstag her
    }
}, 20 );
```

An empty value means the plugin knows of no affiliate click, so the network's own cookie decides, as before.

> [!WARNING]
> Pixels that another plugin inserts by itself (for example Grow by Tradedoubler, which reports from the thank-you page on its own) are not controlled by this setting. Ask that network how to make them conditional.

## What data the plugin sends

The anonymous click ID, order number, amount excluding VAT, currency and line items (with the price on the order, before discounts) – plus a one-way fingerprint (SHA-256) of the billing email, which is only compared with the affiliate's own email to catch self-referrals. The email address itself is never sent, and no names, addresses or payment details are sent.

From version 1.11.0 the plugin also sends: that an affiliate click has been stored (only the click ID and your store), and the order's discount codes. An order without a click is only sent with the personal codes that matched.

## Lead programs

The plugin reports purchases, not sign-ups. If your program pays per lead, use the script instead:

1. Install the free **WPCode** plugin: **Plugins → Add New Plugin**, search for "WPCode" and activate it.
2. Paste the tracking code from **Setup** into **Code Snippets → Header & Footer**, in the **Header** field, so the click is remembered across the whole site.

To count leads without any more code, enter the address of your thank-you page under **Automatic lead tracking** in **Setup** before you copy the tracking code – the code then carries the thank-you page's address (`data-lead-url`). If you leave the field empty, Setup shows a lead script for the thank-you page instead.

Source: https://www.affilyflow.com/en/docs/store/woocommerce
