AFFNHelp centerSign in

WooCommerce setup

About 5 minutes. One snippet captures the click, saves it on the order, and reports the sale.

1. Set your offer's landing URL

https://yourstore.com/?s2s_click={click_id}

2. Add the snippet

  1. 1
    Install the free Code Snippets plugin, or use your child theme's functions.php.
  2. 2
    Add a new snippet, paste the code below, set it to Run everywhere, and activate it.
PHP snippet
<?php // AFFN conversion tracking for WooCommerce const NB_POSTBACK = 'https://affn.io/api/public/postback'; // 1) Remember the click ID for 30 days when a visitor lands add_action('init', function () { if (!empty($_GET['s2s_click'])) { $id = sanitize_text_field(wp_unslash($_GET['s2s_click'])); if (preg_match('/^[0-9a-f-]{36}$/i', $id)) { setcookie('s2s_click', $id, time() + 30 * DAY_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN, is_ssl(), true); $_COOKIE['s2s_click'] = $id; } } }); // 2) Save it on the order at checkout add_action('woocommerce_checkout_create_order', function ($order) { if (!empty($_COOKIE['s2s_click'])) { $order->update_meta_data('_s2s_click', sanitize_text_field($_COOKIE['s2s_click'])); } }); // 3) Fire the postback once, when the order is paid add_action('woocommerce_payment_complete', 'nb_send_postback'); add_action('woocommerce_order_status_completed', 'nb_send_postback'); function nb_send_postback($order_id) { $order = wc_get_order($order_id); if (!$order || $order->get_meta('_nb_sent')) return; $click = $order->get_meta('_s2s_click'); if (!$click) return; $url = add_query_arg(['click_id' => $click], NB_POSTBACK); // Optional: pay 10% of the subtotal instead of the offer default // Percent rules use the amount: $url = add_query_arg(['amount' => $order->get_subtotal(), 'order_id' => $order->get_id()], $url); $res = wp_remote_get($url, ['timeout' => 10]); $code = wp_remote_retrieve_response_code($res); if ($code === 200 || $code === 409) { $order->update_meta_data('_nb_sent', 1); $order->save(); } $order->add_order_note('AFFN postback: HTTP ' . $code); }

How it behaves

The postback fires once, when payment completes or the order is marked Completed. It never fires twice for the same order. Each result is logged as an order note.

Refunds and cancellations: open the conversion in AFFN and choose Hold. To hold every sale until your return window ends, add status=pending to the URL and approve later.

Caching plugins: if you use full-page caching, exclude pages whose URL contains s2s_click so the cookie still gets set.

Test your setup
  • Open a partner link: your browser now has an s2s_click cookie
  • Place a test order and mark it paid or completed
  • The order notes show 'AFFN postback: HTTP 200'
  • The conversion appears under Conversions in AFFN