This is the full altered code for this portion of GA code:
Code:
<!-- Google ecommerce tracking -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXX-1']);
_gaq.push(['_trackPageview']);
_gaq.push(['_addTrans',
'<?php print $SC['order_placed']['number'] ?>', // order ID - required
'Your Name Here', // affiliation or store name
'<?php print $SC['order_placed']['grand_total'] ?>', // total - required
'<?php print $SC['order_placed']['tax_total'] ?>', // tax
'<?php print $SC['order_placed']['shipping_total'] ?>', // shipping
'<?php print htmlentities($SC['order_placed']['address']['Bill_City'],ENT_QUOTES) ?>', // city
'<?php print htmlentities($SC['order_placed']['address']['Bill_State_Name'],ENT_QUOTES) ?>', // state or province
'<?php print htmlentities($SC['order_placed']['address']['Bill_Country_Name'],ENT_QUOTES) ?>' // country
]);
<?php foreach($SC['order_placed']['items'] as $item) { ?>
_gaq.push(['_addItem',
'<?php print $SC['order_placed']['number'] ?>', // order ID - required
'<?php print $item['record_number'].'-'.htmlentities($item['SKU'],ENT_QUOTES).'-'.htmlentities($item['Product_Code'],ENT_QUOTES).'-'.$item['hash'] ?>', // SKU/code - required
'<?php print htmlentities($item['Name'],ENT_QUOTES) ?>', // product name
'<?php print $item['primary_category'].'-'.htmlspecialchars(get_field_val('Categories','Name','record_number = '.$item['primary_category']),ENT_QUOTES); ?>', // category or variation
'<?php print $item['total'] ?>', // unit price - required
'<?php print $item['qty'] ?>' // quantity - required
]);
<?php } ?>
_gaq.push(['_trackTrans']); //submits transaction to the Analytics servers
</script>
Notice a couple others alterations: - State and Country use a different field, as the original code only added the database record number, not a textual value.
- Category and Product values are slightly expanded to make them more useful.
- Some conservative escaping of potential html characters.