WooCommerce script

Please see the following WooCommerce page for their documentation regarding their WC_Order Class:

http://docs.woothemes.com/wc-apidocs/class-WC_Order.html

 

This is an example script that shows how to integrate the correct variables into the AvantMetrics.push Order Confirmation script.

 

<?php
$one = $order->order_tax;
$two=$order->order_shipping;
$three=$order->order_shipping_tax;
$four=$order->order_total;
$Total_Tax_Shipping=$one+$two+$three;
$Av_Subtotal = $four-$Total_Tax_Shipping;

if ( $order->get_items() ) {
foreach ( $order->get_items() as $item ) {
$_product = $order->get_product_from_item( $item );
$code .= "_AvantMetrics.push(['item',{ order_id:";
$code .= $order->id.",parent_sku:";
$code .= "'" . esc_js( $_product->get_sku() ? __( 'SKU:', 'woocommerce' ) . ' ' . $_product->get_sku() : $_product->id ) . "',";
$code .= "variant_sku:'none',price:'".esc_js( $order->get_item_total( $item ) ). "',qty:'".esc_js($item['qty'])."'}]);";
}
}
echo "<script> var _AvantMetrics = _AvantMetrics || [];";
echo "_AvantMetrics.push(['order',{ order_id:";
echo $order->id;
echo ", amount:";
echo "'".$Av_Subtotal."'";
echo ", state:";
echo "'".$order->billing_state."'";
echo ", country:";
echo "'".$order->billing_country."'";
echo "}]);";
echo $code;
echo "</script>";
?>:

 

Instructions

• This is a snapshot of where you should replace your existing code snippet on WooCommerce's thankyou.php page.
•  Within Wordpress, it is normally located here --> woocommerce/templates/checkout/thankyou.php
•  But, if you are using a child theme it could be elsewhere. This page is accessed via Plugins->Editor->Woocommerce.
•  Note: The thankyou.php file is normally not displayed in the right hand list when you hit the Edit Woocommerce screen.
•  I usually have to scroll down 3/4 of the file list and find the "woocommerce/templates/content-single-product.php" file and click on it.
•  This will now bring up a new list of files with the one we want. "woocommerce/templates/content-single-product.php".
•  Click this file (usually the 9th one down).
•  Now, refer to the script above and locate the area in your thankyou.php editor. Replace any existing tracking code referenced with the above.
•   Make sure to hit the Update File to save your changes.
•   Run a tracking test.

Have more questions? Submit a request
Powered by Zendesk