Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of WooCommerce Conversion Tracking for Products
function prefix_service_conversion_tracking( $order_id ) {
// Lets grab the order
$order = new WC_Order( $order_id );
// Products
$products = $order->get_items();
?>
<script>
window['service'].push(['track', 'products', [
<?php
$count = 0;
foreach( $products as $item_id => $item ) {
$count++;
$product = $order->get_product_from_item( $item ); ?>
{
sku: '<?php echo $product->get_sku(); ?>',
price: '<?php echo $order->get_line_subtotal( $item ); ?>',
quantity: '<?php echo $item['qty']; ?>'
}<?php if ( count( $order->get_items() ) > $count ) { echo ","; } ?>
<?php } ?>
]]);
</script>
<?php
}
add_action( 'woocommerce_thankyou', 'prefix_service_conversion_tracking' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.