Working with WooCommerce

When working with a WooCommerce installation to track sales for partners, you only need to add a small piece of code to your thank you page that passes through the sale amount and order ID for reference in your conversion report.

First, access the WordPress admin interface and go to Appearance > Editor from the main navigation. On the right side of the editor page is a list of files for the activated theme. Click the “Theme Functions (functions.php)” file.

In this file, you need to add a way to send information from WooCommerce to TUNE. One way to do this is to assemble and fire a conversion using your network ID, your offer ID, the order subtotal, and the order number.

To do so, paste in the following code at the top of the file, after the <?php line:

add_action( 'woocommerce_thankyou', 'my_custom_tracking' );

function my_custom_tracking( $order_id ) {
  $order = wc_get_order( $order_id );
  $total = $order->get_subtotal();
  $order_num = str_replace('#', '', $order->get_order_number());
  echo '<iframe src="' . $total . '&adv_sub=' . $order_num . '" scrolling="no" frameborder="0" width="1" height="1"></iframe>';

Replace “NETWORKID” and “OFFERID” with the appropriate network ID and offer ID from your network. Save the “functions.php” file and the tracking code is ready for test conversions.

For other questions about the WooCommerce API, reference their official documentation.