下面有一个脚本,我确实集成到woocommerce的“谢谢”页面,我不知道要显示orderID
和orderValue
的内容,有人可以帮我吗?
(function() {
function c(t) {
for (var n = document.cookie.split(";"), r = 0; r < n.length; r++)
if (p = n[r].split("="), p[0] == t)
return p[1];
return ''
}
adrecord = {
"programID": 15,
"orderID": "HERE I NEED TO SHOW orderID (order number)",
"orderValue": HERE I NEED TO SHOW orderValue inc tax,
"trackID": c('trackID'),
"source": c('source')
};
var e = document.createElement('script');
e.src = 'https://track.adrecord.com/track.js';
var s = document.getElementsByTagName('script')[0];
s.appendChild(e);
})();
感谢您的帮助。
答案 0 :(得分:0)
您可以在woocommerce_thankyou操作挂钩中使用以下挂钩函数,该挂钩函数将在Javascript中设置正确的订单ID和总数:
add_action( 'woocommerce_thankyou', 'thankyou_tracking_script', 10, 1 );
function thankyou_tracking_script( $order_id ) {
// Get the WC_Order instance Object
$order = wc_get_order( $order_id );
// Output Javascript
?>
<!-- JS Order received Script -->
<script type="text/javascript">
(function() {
function c(t) {
for (var n = document.cookie.split(";"), r = 0; r < n.length; r++)
if (p = n[r].split("="), p[0] == t) return p[1];
return ''
}
adrecord = {
"programID": 15,
"orderID": "<?php echo $order_id; ?>",
"orderValue": <?php echo $order->get_total(); ?>,
"trackID": c('trackID'),
"source": c('source')
};
var e = document.createElement('script');
e.src = 'https://track.adrecord.com/track.js';
var s = document.getElementsByTagName('script')[0];
s.appendChild(e);
})();
</script>
<?php
}
代码进入您的活动子主题(或活动主题)的function.php文件中。经过测试,可以正常工作。
或使用wp_footer
动作钩子定位到“收到订单” (谢谢)页面的类似代码:
add_action( 'wp_footer', 'order_received_tracking_script' );
function order_received_tracking_script() {
// Only on "Order received" page
if( ! is_wc_endpoint_url('order-received') ) Return; // Exit
$order_id = absint( $wp->query_vars['order-received'] );
// Get the WC_Order instance Object
$order = wc_get_order( $order_id );
// Output Javascript
?>
<!-- JS Order received Script -->
<script type="text/javascript">
(function() {
function c(t) {
for (var n = document.cookie.split(";"), r = 0; r < n.length; r++)
if (p = n[r].split("="), p[0] == t) return p[1];
return ''
}
adrecord = {
"programID": 15,
"orderID": "<?php echo $order_id; ?>",
"orderValue": <?php echo $order->get_total(); ?>,
"trackID": c('trackID'),
"source": c('source')
};
var e = document.createElement('script');
e.src = 'https://track.adrecord.com/track.js';
var s = document.getElementsByTagName('script')[0];
s.appendChild(e);
})();
</script>
<?php
}
代码进入您的活动子主题(或活动主题)的function.php文件中。经过测试,可以正常工作。