Article

C2S – WooCommerce – Manual

The manual integration for WooCommerce replaces the Affilae plugin: you install the tracking tag and the conversion code in your WordPress theme yourself. It requires two codes, one on all pages, the other in the functions.php file.

Prerequisites: the URL format of your program must be set as a Parameter. You can change the URL format by going to your program Configuration and editing the Global settings. You also need access to your WordPress theme editor.
Good to know: if you can install the Affilae plugin, prefer it. It does the same job without touching your theme code. See C2S – WooCommerce.

Track partner clicks

This code goes on all pages of your website, inside the <body> tag.

Where to install the code, via the theme

  1. Go to WordPress Admin > Appearance > Theme Editor.
  2. Select header.php or theme.php.
  3. Add the code inside the <body> tag.

Code to install:

<script type="text/javascript">
var _ae = {
"pid":"PROGRAM_ID",
};
(function() {
var element = document.createElement('script'); element.type = 'text/javascript'; element.async = true;
element.src = '//static.affilae.com/ae-v3.5.js';
var scr = document.getElementsByTagName('script')[0]; scr.parentNode.insertBefore(element, scr);
})();
</script>

Where to find your Program ID? Affilae Admin > Configuration > Tracking tab > Integration via an Affilae plugin section. Replace PROGRAM_ID with that value.

Track sales

This code goes in the functions.php file of your WordPress theme. It fires on the WooCommerce thank-you page.

Where to install the code

  1. Go to WordPress Admin > Appearance > Theme Editor.
  2. Click Theme Functions (functions.php).
  3. Add the code at the very top, right after the <?php line.

Code to install:

add_action('woocommerce_thankyou', 'Affilae_conversion_tracking');
function Affilae_conversion_tracking($order_id)
{
$order = wc_get_order($order_id);
$order_total = (float) $order->get_total() - $order->get_total_tax() - $order->get_total_shipping(); // Total before shipping cost and discount
$discount_total = $order->get_discount_total();
$total = $order_total - $discount_total;
$order_num = str_replace('#', '', $order->get_order_number());
// Get coupons code if any
$coupons_code = "";
$count = 0;
foreach ($order->get_used_coupons() as $coupon) { // since WC 3.7
$count ;
if ($count > 1) {
$coupons_code .= ';';
}
$coupons_code .= $coupon;
}

$items = $order->get_items();

$product_id = '';
$items = $order->get_items();
$productsIdArray = array();

foreach ($items as $item) {
$productsIdArray[] = $item['product_id'];
}

if (count($productsIdArray) > 0) {
$product_id = implode(';', $productsIdArray);
}

echo '<iframe src="https://lb.affilae.com/?key=YOUR.KEY&id=' . $order_num . '&amount=' . $total . '&payment=online&cv={CUSTOM_VAR}&voucher=' . $coupons_code . '&product=' . $product_id . '" frameborder="0" width="1" height="1"></iframe>';
}

The variable to update

Replace the sample key YOUR.KEY with your conversion key.

Where to find your key? Affilae Admin > Configuration > Tracking tab > Integration via an Affilae plugin section. Select the matching rule, then copy its Key.

What the conversion code does

It automatically reports the following data, with nothing for you to fill in.

  • The unique order number.
  • The net amount, excluding taxes and shipping fees.
  • The promo codes used.
  • The IDs of the purchased products.
  • The applied discounts.

Three calculation rules to keep in mind.

  • Final amount = total price, minus taxes, minus shipping fees, minus discounts.
  • Multiple products: a list separated by a semicolon.
  • Multiple promo codes: a list separated by a semicolon.

Your installation checklist

Installation

  • Tracking code added to all pages.
  • Conversion code added in functions.php.
  • Variables replaced with actual values.

Test

  • Click and conversion tests performed.
  • Verified in the Affilae dashboard.
  • Test documentation followed.
Tip: test with a real order, not only with a click. The conversion code only fires on the WooCommerce thank-you page, so an abandoned cart proves nothing.

Related articles

Frequently asked
questions

Verify that the Program ID is correct. Then make sure the code is present on all pages of the site, not only on the home page.

Verify that the conversion key is correct, then that the code is in functions.php. Test with a real order, and make sure WooCommerce is up to date.

The plugin does the same job without you touching your theme code, and it is configured from the WordPress admin. The manual integration is for cases where you cannot install the plugin, or where your theme needs a custom setup.

The final amount sent is the total order price, minus taxes, minus shipping fees, minus discounts. That value is the basis for the commission calculation.

As a list separated by a semicolon. The conversion code assembles the product IDs and the promo codes of the order by itself.

In Affilae, open your program Configuration, then the Tracking tab. The Integration via an Affilae plugin section shows the Program ID and, for each selected rule, its Key.

Need help?

Stay up to date with the latest trends in affiliate marketing and never miss any of our articles.

Contact Us