gtm4wp_woocommerce_cart_item_product_filter

The Google Tag Manager for WordPress gtm4wp woocommerce cart item product filter function.

Description

gtm4wp_woocommerce_cart_item_product_filter( $product, (string) $cart_item = '', (string) $cart_id = '' ); 

Parameters (3)

0. $product
The product.
1. $cart_item — Optional. (string) => ''
The cart item.
2. $cart_id — Optional. (string) => ''
The cart id.

Usage

  1. if ( !function_exists( 'gtm4wp_woocommerce_cart_item_product_filter' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-tag-manager-for-wordpress/integration/woocommerce.php'; 
  3.  
  4. // The product. 
  5. $product = null; 
  6.  
  7. // The cart item. 
  8. $cart_item = ''; 
  9.  
  10. // The cart id. 
  11. $cart_id = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = gtm4wp_woocommerce_cart_item_product_filter($product, $cart_item, $cart_id); 
  15.  

Defined (1)

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

/integration/woocommerce.php  
  1. function gtm4wp_woocommerce_cart_item_product_filter( $product, $cart_item="", $cart_id="" ) { 
  2. global $gtm4wp_options; 
  3.  
  4. $product_id = $product->get_id(); 
  5. $_product_cats = get_the_terms($product->id, 'product_cat'); 
  6. if ( ( is_array( $_product_cats ) ) && ( count( $_product_cats ) > 0 ) ) { 
  7. $product_cat = array_pop( $_product_cats ); 
  8. $product_cat = $product_cat->name; 
  9. } else { 
  10. $product_cat = ""; 
  11.  
  12. $remarketing_id = $product_id; 
  13. $product_sku = $product->get_sku(); 
  14. if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] && ( "" != $product_sku ) ) { 
  15. $remarketing_id = $product_sku; 
  16.  
  17. $_temp_productdata = array( 
  18. "id" => $remarketing_id,  
  19. "name" => $product->post->post_title,  
  20. "price" => $product->get_price(),  
  21. "category" => $product_cat,  
  22. "productlink" => apply_filters( 'the_permalink', get_permalink(), 0) 
  23. ); 
  24.  
  25. if ( "variation" == $product->product_type ) { 
  26. $_temp_productdata[ "variant" ] = implode(", ", $product->get_variation_attributes()); 
  27. } else { 
  28. $_temp_productdata[ "variant" ] = ""; 
  29.  
  30. $eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, "cart" ); 
  31. $GLOBALS["gtm4wp_cart_item_proddata"] = $eec_product_array; 
  32.  
  33. return $product;