I have a custom thank you page for after checkout is finished in WooCommerce where I need to insert order data into a Google ecommerce tracking tag to record the sale in analytics. One part of that is adding the following for each item in the order...
ga('ecommerce:addItem', {
'id': <?php echo $order_id?>, // Transaction ID. Required.
'name': 'ACME Product', // Product name. Required.
'sku': '1234', // SKU/code.
'category': 'Product Category', // Category or variation.
'price': '10.00', // Unit price.
'quantity': '1' // Quantity.
});
but with inserting the order item's real data using PHP, not the placeholders you see there for name, sku, category, price, and quantity.
In Googling around for answers, I see that I must now use
wc_display_item_meta ( $item );
rather than the deprecated $item_meta = new WC_Order_Item_Meta( $item['item_meta'], $_product );
What I need help with, because I don't yet fully know PHP and I can't seem to find any close examples, is how do I begin to grab the values? Is it a foreach of some kind, or is there a way to directly parse out each item's individual properties out of the order item into a variable that I can then insert in these placeholders?