/**
* Adds code to track Webgains
*
*/
// Include Webgains container tag script within head of very page
wp_enqueue_script('webgains-script', '//tag.webgains.com/container-XXXX.html', array(), '1', false);
// Include Webgains tracking script on order confirmation page
add_action('woocommerce_thankyou', 'wg_tracking', 10, 1);
function wg_tracking( $orderid ) {
$order = new WC_Order($orderid);
$order_number = $order->get_order_number();
$total = $order->get_total();
$currency = $order->get_order_currency();
if( $order->get_used_coupons() ) {
$coupons_count = count( $order->get_used_coupons() );
echo '<h4>' . __('Coupons used') . ' (' . $coupons_count . ')</h4>';
echo '<p><strong>' . __('Coupons used') . ':</strong> ';
$i = 1;
$coupons_list = '';
foreach( $order->get_used_coupons() as $coupon) {
$coupons_list .= $coupon;
if( $i < $coupons_count )
$coupons_list .= ', ';
$i++;
}
} // endif get_used_coupons
?>
<!-- <webgains tracking code> -->
<script language="javascript" type="text/javascript">
var wgOrderReference = "<?php echo $order_number?>";
var wgOrderValue = "<?php echo $total?>";
var wgEventID = XXXX;
var wgComment = "";
var wgLang = "en_EN";
var wgsLang = "javascript-client";
var wgVersion = "1.2";
var wgProgramID = XXXX;
var wgSubDomain = "track";
var wgCheckSum = "";
var wgItems = "";
var wgVoucherCode = "<?php echo $coupons_list?>";
var wgCustomerID = "";
var wgCurrency = "<?php echo $currency?>";
if(location.protocol.toLowerCase() == "https:") wgProtocol="https";
else wgProtocol = "http";
wgUri = wgProtocol + "://" + wgSubDomain + ".webgains.com/transaction.html" + "?wgver=" + wgVersion + "&wgprotocol=" + wgProtocol + "&wgsubdomain=" + wgSubDomain + "&wgslang=" + wgsLang + "&wglang=" + wgLang + "&wgprogramid=" + wgProgramID + "&wgeventid=" + wgEventID + "&wgvalue=" + wgOrderValue + "&wgchecksum=" + wgCheckSum + "&wgorderreference=" + wgOrderReference + "&wgcomment=" + escape(wgComment) + "&wglocation=" + escape(document.referrer) + "&wgitems=" + escape(wgItems) + "&wgcustomerid=" + escape(wgCustomerID) + "&wgvouchercode=" + escape(wgVoucherCode) + "&wgCurrency=" + escape(wgCurrency);
document.write('<sc'+'ript language="JavaScript" type="text/javascript" src="'+wgUri+'"></sc'+'ript>');
</script>
<noscript>
<?php echo '<img src="https://track.webgains.com/transaction.html?wgver=1.2&wgprogramid=XXXX&wgrs=1&wgvalue=' . $total . '&wgeventid=XXXX&wgorderreference=' . $order_number . '&wgitems=&wgvouchercode=' . $coupons_list . '&wgcustomerid=&wgCurrency=' . $currency . '" alt="" />' ?>
</noscript>
<!-- </webgains tracking code> -->
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.