Updated e-commerce tracking.

- update SKU in e-commerce tracking (fallback on ID if SKU is empty)
- Add category tree if not a variant
This commit is contained in:
Jeroen Diderik 2012-03-15 18:35:13 +01:00
parent 82e4ec543b
commit 3a712ac932
1 changed files with 12 additions and 2 deletions

View File

@ -1129,9 +1129,19 @@ function woocommerce_ecommerce_tracking( $order_id ) {
<?php if ($order->get_items()) foreach($order->get_items() as $item) : $_product = $order->get_product_from_item( $item ); ?>
_gaq.push(['_addItem',
'<?php echo $order_id; ?>', // order ID - required
'<?php echo $_product->sku; ?>', // SKU/code - required
'<?php if (isset($_product['sku']) && !empty($_product['sku'])){ echo $_product->sku; } else { echo $_product->id; }; ?>', // SKU/code - required
'<?php echo $item['name']; ?>', // product name
'<?php if (isset($_product->variation_data)) echo woocommerce_get_formatted_variation( $_product->variation_data, true ); ?>', // category or variation
'<?php if (isset($_product->variation_data)){
echo woocommerce_get_formatted_variation( $_product->variation_data, true );
} else {
$out = array();
$categories = get_the_terms($_product->id, 'product_cat');
foreach ( $categories as $category ){
$out[] = $category->name;
}
echo join( "/", $out);
}
?>', // category or variation
'<?php echo ($item['line_total']/$item['qty']); ?>', // unit price - required
'<?php echo $item['qty']; ?>' // quantity - required
]);