Data layer variable
-
Hello, can you tell me the php variable to push the brand into data layer?
I tried something like
<script> window.dataLayer = window.dataLayer || []; dataLayer.push({ 'event' : 'acquisto', 'ecommerce': { 'currencyCode': '<?php echo $order->get_order_currency(); ?>', 'purchase': { 'actionField':{ 'id': '<?php echo $order->get_order_number(); ?>', 'affiliation': 'WooCommerce', 'revenue': <?php echo number_format($order->get_subtotal(), 2, ".", ""); ?>, 'tax': <?php echo number_format($order->get_total_tax(), 2, ".", ""); ?>, 'shipping': <?php echo number_format($order->calculate_shipping(), 2, ".", ""); ?>, <?php if($order->get_used_coupons()): ?> 'coupon': '<?php echo implode("-", $order->get_used_coupons()); ?>' <?php endif; ?> }, 'products': [ <?php foreach($order->get_items() as $key => $item): $product = $order->get_product_from_item( $item ); $variant_name = ($item['variation_id']) ? wc_get_product($item['variation_id']) : ''; ?> { 'name': '<?php echo $item['name']; ?>', 'id': '<?php echo $item['product_id']; ?>', 'price': '<?php echo number_format ($product->get_sale_price(), 2, ".", ""); ?>', 'variant': '<?php echo ($variant_name) ? implode("-", $variant_name->get_variation_attributes()) : ''; ?>', 'brand': '<?php echo $brands['name']; ?>', 'quantity': <?php echo $item['qty']; ?> }, <?php endforeach; ?> ] } } }); </script>
but i gut empty field in data layer.
The page I need help with: [log in to see the link]
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Data layer variable’ is closed to new replies.