Last active
February 7, 2018 16:54
-
-
Save davecurrierseo/db8de97629eee10560c21422736b9382 to your computer and use it in GitHub Desktop.
Add Tracking Code With Dynamic Variable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Random Tracking Code | |
*/ | |
/** | |
* Adds Tracking script to footer of thank-you page | |
*/ | |
function coa_add_trackingCode($order_id) { | |
$order = wc_get_order($order_id); | |
$order_number = $order->get_order_number(); | |
$trackingCode_store_id = 'XXXXXX'; | |
echo <<<END | |
<div class="code-cta" style="width: 500px; margin: 0 auto;"> | |
<script type="text/javascript"> | |
var _cnx = _cnx || []; | |
_cnx.push(['mid', {$trackingCode_store_id}]); | |
_cnx.push(['surveyType', 'pos']); | |
_cnx.push(['orderId', '{$order_number}']); | |
(function (w, d, t) { | |
var s = d.createElement(t); | |
s.async = true; | |
s.src = '//example.com/js/init.js'; | |
var h = d.getElementsByTagName(t)[0]; h.parentNode.insertBefore(s, h); | |
})(window, document, 'script'); | |
</script> | |
</div> | |
END; | |
} | |
add_action('woocommerce_thankyou', 'coa_add_trackingCode'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment