Horje
enhanced ecommerce data layer for woocommerce Code Example
enhanced ecommerce data layer for woocommerce
<script>
      dataLayer.push({
          '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($order->get_line_subtotal($item), 2, ".", ""); ?>',
                        'brand': '',
                        'category': '<?php echo strip_tags($product->get_categories(', ', '', '')); ?>',
                        'variant': '<?php echo ($variant_name) ? implode("-", $variant_name->get_variation_attributes()) : ''; ?>',
                        'quantity': <?php echo $item['qty']; ?>
                      },
                  <?php endforeach; ?>
                ]
            }
          }
      });
    </script>




Php

Related
ultimo numeto php Code Example ultimo numeto php Code Example
php version 7.4 Code Example php version 7.4 Code Example
Passing values to blade using redirect() and back() functions Code Example Passing values to blade using redirect() and back() functions Code Example
php mail merge docx document Code Example php mail merge docx document Code Example
tinker laravel 8 Code Example tinker laravel 8 Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7