xlplugins
9/13/2017 - 6:42 AM

Add PostAffTracker scripts on WooCommerce Thank you page after order completes

Add PostAffTracker scripts on WooCommerce Thank you page after order completes

<?php
/**
 * Adding PostAffTracker script on thank you page.
 * Works with WooCommerce 3.0 or above
 */
add_action("woocommerce_thankyou", "xlwcty_add_postafftracker_script", 20);

if(!function_exists('xlwcty_add_postafftracker_script')) {
    function xlwcty_add_postafftracker_script($order_id) {

        if ($order_id > 0) {
            $order = wc_get_order($order_id);
            if ($order instanceof WC_Order) {
                ?>
                <script id="pap_x2s6df8d" src="https://vapourdepot.postaffiliatepro.com/scripts/dzfj24z0" type="text/javascript">
                </script>
                <script type="text/javascript">
                    PostAffTracker.setAccountId('default1');
                    var sale = PostAffTracker.createSale();
                    sale.setTotalCost('<?php echo ($order->get_total() - $order->get_shipping_total()); ?>');
                    sale.setOrderID('<?php echo $order->get_id(); ?>');
                    sale.setCurrency('<?php echo $order->get_currency(); ?>');
                    PostAffTracker.register();
                </script>
                <?php
            }
        }
    }
}