Created
June 29, 2015 17:49
-
-
Save devinsays/d65db56ad333782e9424 to your computer and use it in GitHub Desktop.
Example of WooCommerce Conversion Tracking for Products
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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