wc_track_product_view

Track product views.

Description

wc_track_product_view(); 

Usage

  1. if ( !function_exists( 'wc_track_product_view' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-product-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wc_track_product_view(); 
  7.  

Defined (1)

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

/includes/wc-product-functions.php  
  1. function wc_track_product_view() { 
  2. if ( ! is_singular( 'product' ) || ! is_active_widget( false, false, 'woocommerce_recently_viewed_products', true ) ) { 
  3. return; 
  4.  
  5. global $post; 
  6.  
  7. if ( empty( $_COOKIE['woocommerce_recently_viewed'] ) ) 
  8. $viewed_products = array(); 
  9. else 
  10. $viewed_products = (array) explode( '|', $_COOKIE['woocommerce_recently_viewed'] ); 
  11.  
  12. if ( ! in_array( $post->ID, $viewed_products ) ) { 
  13. $viewed_products[] = $post->ID; 
  14.  
  15. if ( sizeof( $viewed_products ) > 15 ) { 
  16. array_shift( $viewed_products ); 
  17.  
  18. // Store for session only 
  19. wc_setcookie( 'woocommerce_recently_viewed', implode( '|', $viewed_products ) );