1
我一直致力於在我的woocommerce網站上製作新的Facebook像素跟蹤代碼功能。我有一些事情我想要做,並且我開始了我認爲最容易的地方。首先,我想更改此代碼以使用結算小計而不是訂單總額,因爲我使用了存款,這會將訂單總額更改爲實際價格的20%。其次,我使用了像素跟蹤插件,並且我想將此功能添加到插件中以便能夠快速將其插入到其他頁面中。我已經成功地能夠得到的代碼中加入這functions.php的工作:Woocommerce Facebook新的像素跟蹤代碼將購買添加到價值
// Add purchase code to order received page
function checkout_analytics($order_id) {
$order = new WC_Order($order_id);
$currency = $order->get_order_currency();
$total = $order->get_total();
$date = $order->order_date;
?>
<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','https://connect.facebook.net/en_US/fbevents.js');
fbq('init', 'XXXXXXXXXX'); // Insert your pixel ID here.
</script>
<script>
fbq('track', 'Purchase', {
value: <?php echo $order->get_total(); ?>,
currency: 'USD'
});
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=XXXXXXXXXX&ev=PageView&noscript=1"
/></noscript>
<!-- DO NOT MODIFY -->
<!-- End Facebook Pixel Code -->
<?php
}
add_action('woocommerce_thankyou', 'checkout_analytics');
所以要嘗試並獲得訂單小計我已經改變了這樣的代碼,這是行不通的。它不會拉小計的價值,我想我在這裏有一些格式問題。 Pixel error picture
// Add purchase code to order received page
function checkout_analytics($order_id) {
$order = new WC_Order($order_id);
$currency = $order->get_order_currency();
$total = $order->get_total();
$date = $order->order_date;
$cart_subtotal = $order->subtotal_ex_tax;
?>
<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','https://connect.facebook.net/en_US/fbevents.js');
fbq('init', 'XXXXXXXXXXXXXX'); // Insert your pixel ID here.
</script>
<script>
fbq('track', 'Purchase', {
value: <?php echo $order->subtotal_ex_tax; ?>,
currency: 'USD'
});
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=XXXXXXXXX&ev=PageView&noscript=1"
/></noscript>
<!-- DO NOT MODIFY -->
<!-- End Facebook Pixel Code -->
<?php
}
add_action('woocommerce_thankyou', 'checkout_analytics');
我想獲得的代碼工作正常,那麼我想添加到一個插件這一點,但我不知道該怎麼做完全。我的模糊想法是複製函數,但我覺得這不會完全奏效。
你應該接受你的答案,點擊旁邊左側(上)側的灰色複選標記圖標。謝謝 – LoicTheAztec
會這樣做,只需要等2天就可以了 –