gtm4wp_woocommerce_after_template_part

The Google Tag Manager for WordPress gtm4wp woocommerce after template part function.

Description

gtm4wp_woocommerce_after_template_part( (string) $template_name ); 

Parameters (1)

0. $template_name (string)
The template name.

Usage

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

Defined (1)

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

/integration/woocommerce.php  
  1. function gtm4wp_woocommerce_after_template_part( $template_name ) { 
  2. global $product, $gtm4wp_product_counter, $gtm4wp_last_widget_title, $gtm4wp_options; 
  3.  
  4. $productitem = ob_get_contents(); 
  5. ob_end_clean(); 
  6.  
  7. if ( "content-widget-product.php" == $template_name ) { 
  8. $product_id = $product->get_id(); 
  9. $_product_cats = get_the_terms($product->id, 'product_cat'); 
  10. if ( ( is_array( $_product_cats ) ) && ( count( $_product_cats ) > 0 ) ) { 
  11. $product_cat = array_pop( $_product_cats ); 
  12. $product_cat = $product_cat->name; 
  13. } else { 
  14. $product_cat = ""; 
  15.  
  16. $remarketing_id = $product_id; 
  17. $product_sku = $product->get_sku(); 
  18. if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSESKU ] && ( "" != $product_sku ) ) { 
  19. $remarketing_id = $product_sku; 
  20.  
  21. $_temp_productdata = array( 
  22. "id" => $remarketing_id,  
  23. "name" => $product->post->post_title,  
  24. "price" => $product->get_price(),  
  25. "category" => $product_cat,  
  26. "productlink" => apply_filters( 'the_permalink', get_permalink(), 0),  
  27. "listname" => $gtm4wp_last_widget_title,  
  28. "listposition" => $gtm4wp_product_counter 
  29. ); 
  30. $eec_product_array = apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, "widgetproduct" ); 
  31.  
  32. $productlink_with_data = sprintf('data-gtm4wp_product_id="%s" data-gtm4wp_product_name="%s" data-gtm4wp_product_price="%s" data-gtm4wp_product_cat="%s" data-gtm4wp_product_url="%s" data-gtm4wp_productlist_name="%s" data-gtm4wp_product_listposition="%s" class="widget-product-item" href="',  
  33. esc_attr( $eec_product_array[ "id" ] ),  
  34. esc_attr( $eec_product_array[ "name" ] ),  
  35. esc_attr( $eec_product_array[ "price" ] ),  
  36. esc_attr( $eec_product_array[ "category" ] ),  
  37. esc_url( $eec_product_array[ "productlink" ] ),  
  38. esc_attr( $eec_product_array[ "listname" ] ),  
  39. esc_attr( $eec_product_array[ "listposition" ] ) 
  40. ); 
  41.  
  42. $gtm4wp_product_counter++; 
  43.  
  44. $productitem = str_replace( 'href="', $productlink_with_data, $productitem ); 
  45.  
  46. echo $productitem;