Search
 
SCRIPT & CODE EXAMPLE
 

PHP

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>
Comment

PREVIOUS NEXT
Code Example
Php :: update query not working no errors found php mysql 
Php :: Attempt to read property "headers" on string 
Php :: clear laravel cache and clear vue 
Php :: Change Initial Country For Caldera Forms Phone Fields 
Php :: static functions php 
Php :: update php 7.2 centos 8 command line without sudo 
Php :: repalce 0 in phone with 234 
Php :: yii2 modules commands are not showing in console 
Php :: wordpress remove current post in sidebar php 
Php :: mongodb uploading csv php 
Php :: how can we send attached file with notification in gmail in laravel 8 
Php :: create global function laravel 
Php :: comment php laravel template blade 
Php :: send emails with runtime configurations in laravelk 
Php :: foreach in json object php 
Php :: omnipay capture 
Php :: many to many relationship laravel example 
Php :: wp wc php change customer shipping country for all users 
Php :: way to convert an integer to an array of numbers 
Php :: laravel 8 api validation 
Php :: larqavel migration 
Php :: if ( $post_armi-have_posts() ) { while ($post_armi-have_posts() ) { $post_armi-the_post(); 
Php :: php async curl request 
Php :: how to search like username,email and phone number in php 
Php :: mysql_query not working in php 7 
Php :: Dein Benutzer-Profil um weitere Social Media Accounts erweitern 
Php :: laravel blade all syntex description 
Php :: php slim inspect request method 
Php :: generate hash password in laravel online 
Php :: php git pull webhook 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =