WooCommerce Integration : Helpdesk

WooCommerce Integration

Formatting the script for your account

*IMPORTANT* Here is some base script, below this are the changes you need to apply to it before you add to your thankyou.php file in your woocommerce file manager:

<?php add_action( 'woocommerce_thankyou', 'my_custom_tracking' );

function my_custom_tracking( $order_id ) {
// Lets grab the order
    $order = wc_get_order( $order_id );

    //Everflow order objects
    $efOrder = array();
    $efOrder['items'] = array();
    $efOrder['oid'] = $order_id;
    $efOrder['amt'] = $order->get_total();
    $efOrder['bs'] = $order->get_billing_state();
    $efOrder['bc'] = $order->get_billing_country();

    // Determine if any coupons were used for this transaction
    $coupons = '';
    if( $order->get_used_coupons() ) {
        foreach( $order->get_used_coupons() as $coupon) {
            $coupons .= $coupon.',';
        }
    }
    $efOrder['cc'] = $coupons;

    // This is how to grab line items from the order
    $line_items = $order->get_items();

    // This loops over line items
    $efItems = array();
    foreach ( $line_items as $item ) {
        //Init Everflow item
        $efItem = array();
        // This will be a product
        $product = $order->get_product_from_item( $item );
        // This is the products SKU (variant or parent)
        $efItem['vs'] = '';
        $efItem['ps'] = '';
        if ( $product->get_type() === 'variation' )
        { $efItem['vs'] = $product->get_sku(); }
        else
        { $efItem['ps'] = $product->get_sku(); }
        // This is the qty purchased
        $efItem['qty'] = $item['qty'];
        // Line item total cost including taxes and rounded
        $efItem['p'] = $order->get_line_total( $item, true, true );
        // Add this to Everflow items
        $efItems[] = $efItem;
    }
    $efOrder['items'] = $efItems;
	
	$javascriptCode = '
        <script type="text/javascript" 
    src="https://INSERT_TRACKING_DOMAIN/scripts/sdk/everflow.js"></script>

<script type="text/javascript">
EF.conversion({
    offer_id: INSERT_OFFER_ID,
	amount: '.$order->get_total().',
    adv1: "", //Optional
    adv2: "", //Optional
    adv3: "", //Optional
    adv4: "", //Optional
    adv5: "", //Optional
	order: '.json_encode($efOrder).',
});
</script>';
    echo $javascriptCode;
}
?>	

The offer_id INSERT_ value can be found in the offers > manage > click the offer page here:

 Please also replace INSERT_YOUR_TRACKING_DOMAIN with the tracking domain found in the offers > manage > click the offer and conversion method section here:

Adding the PHP to the correct file in your woocommerce file manager:

In order to add this PHP to the correct file please open up your file manager and find a file called "thankyou.php". Here is how the directory should look like:

Then just place that PHP inside the if statement that will load when a valid order is completed.

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.