gtm4wp_woocommerce_wp_footer

The Google Tag Manager for WordPress gtm4wp woocommerce wp footer function.

Description

gtm4wp_woocommerce_wp_footer(); 

Usage

  1. if ( !function_exists( 'gtm4wp_woocommerce_wp_footer' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-tag-manager-for-wordpress/integration/woocommerce.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = gtm4wp_woocommerce_wp_footer(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/integration/woocommerce.php  
  1. function gtm4wp_woocommerce_wp_footer() { 
  2. global $woocommerce, $gtm4wp_options, $gtm4wp_datalayer_name; 
  3.  
  4. if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC ] ) { 
  5. $( '.add_to_cart_button:not(.product_type_variable, .product_type_grouped)' ).click(function() { 
  6. var productdata = $( this ).closest( '.product' ).find( '.gtm4wp_productdata' ); 
  7.  
  8. ". $gtm4wp_datalayer_name .".push({ 
  9. 'event': 'gtm4wp.addProductToCart',  
  10. 'productName': productdata.data( 'gtm4wp_product_name' ),  
  11. 'productSKU': $( this ).data( 'product_sku' ),  
  12. 'productID': $( this ).data( 'product_id' ),  
  13. }); 
  14. }); 
  15. "); 
  16.  
  17. if ( ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) && ( ! is_cart() ) ) { 
  18. echo " 
  19. <script type='text/javascript'> 
  20. (function($) { 
  21. if ( $( '.gtm4wp_productdata' ).length > 0 ) { 
  22. for( var i=0; i<". $gtm4wp_datalayer_name .".length; i++ ) { 
  23. if ( ". $gtm4wp_datalayer_name ."[ i ][ 'ecomm_prodid' ] ) { 
  24. break; 
  25.  
  26. if ( i == ". $gtm4wp_datalayer_name .".length ) { 
  27. // no existing dyn remarketing data found in the datalayer 
  28. i = 0; 
  29. ". $gtm4wp_datalayer_name ."[ i ][ 'ecomm_prodid' ] = []; 
  30.  
  31. if ( typeof ". $gtm4wp_datalayer_name ."[ i ][ 'ecomm_prodid' ].push == 'undefined' ) { 
  32. return false; 
  33.  
  34. var productdata; 
  35. $( '.gtm4wp_productdata' ).each( function() { 
  36. productdata = jQuery( this ); 
  37.  
  38. ". $gtm4wp_datalayer_name ."[ i ][ 'ecomm_prodid' ].push( productdata.data( 'gtm4wp_product_id' ) ); 
  39. }); 
  40. })(jQuery); 
  41. </script>"; 
  42.  
  43. if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) { 
  44. echo " 
  45. <script type='text/javascript'> 
  46. (function($) { 
  47. if ( $( '.gtm4wp_productdata, .widget-product-item' ).length > 0 ) { 
  48. for( var i=0; i<". $gtm4wp_datalayer_name .".length; i++ ) { 
  49. if ( ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ] ) { 
  50.  
  51. if ( ! ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ][ 'impressions' ] ) { 
  52. ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ][ 'impressions' ] = []; 
  53.  
  54. break; 
  55.  
  56. if ( i == ". $gtm4wp_datalayer_name .".length ) { 
  57. // no existing ecommerce data found in the datalayer 
  58. i = 0; 
  59. ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ] = {}; 
  60. ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ][ 'impressions' ] = []; 
  61.  
  62. ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ][ 'currencyCode' ] = '".get_woocommerce_currency()."'; 
  63.  
  64. var productdata; 
  65. $( '.gtm4wp_productdata, .widget-product-item' ).each( function() { 
  66. productdata = jQuery( this ); 
  67.  
  68. ". $gtm4wp_datalayer_name ."[ i ][ 'ecommerce' ][ 'impressions' ].push({ 
  69. 'name': productdata.data( 'gtm4wp_product_name' ),  
  70. id productdata.data( 'gtm4wp_product_id' ),  
  71. 'price': productdata.data( 'gtm4wp_product_price' ),  
  72. 'category': productdata.data( 'gtm4wp_product_cat' ),  
  73. 'position': productdata.data( 'gtm4wp_product_listposition' ),  
  74. 'list': productdata.data( 'gtm4wp_productlist_name' ) 
  75. }); 
  76. }); 
  77. })(jQuery); 
  78. </script>"; 
  79.  
  80. $( '.add_to_cart_button:not(.product_type_variable, .product_type_grouped)' ).click(function() { 
  81. var productdata = $( this ).closest( '.product' ).find( '.gtm4wp_productdata' ); 
  82.  
  83. ". $gtm4wp_datalayer_name .".push({ 
  84. 'event': 'gtm4wp.addProductToCartEEC',  
  85. 'ecommerce': { 
  86. 'currencyCode': '".get_woocommerce_currency()."',  
  87. 'add': { 
  88. 'products': [{ 
  89. 'name': productdata.data( 'gtm4wp_product_name' ),  
  90. id productdata.data( 'gtm4wp_product_id' ),  
  91. 'price': productdata.data( 'gtm4wp_product_price' ),  
  92. 'category': productdata.data( 'gtm4wp_product_cat' ),  
  93. 'quantity': 1 
  94. }] 
  95. }); 
  96. }); 
  97. ");