Thêm tracking ecommerce Facebook cho wordpress

Mở File functions.php thêm đoạn code sau

<?php
// add the action 
add_action( 'woocommerce_thankyou', 'action_woocommerce_thankyou_tracking', 10, 1 ); 
function action_woocommerce_thankyou_tracking($order_get_id ){
	//create an order instance
    $order = wc_get_order($order_get_id);
	$items = $order->get_items();
	$product_ids = [];
	foreach ( $items as $item ) {
		$product_ids[] = $item->get_product_id();
	}
	?>
<script type="text/javascript">
	fbq('track', 'Purchase',
  // begin required parameter object
  {
    value: <?php echo $order->get_total() ?>,
    currency: 'VND',
    content_type: 'product', // required property
    content_ids: ['<?php echo implode(" ",$product_ids);  ?>']
  }

);
</script>
<?php
}

Tin cùng chuyên mục