title: Woocommerce recently viewed Products
body: <p>I have created a recently viewed script which generated a shortcode which I then inserted into my home page.</p>
  
  <p>The script is designed so that people who may have visited my website and left, once they come back can see instantly what products they had been viewing on their last visit.</p>
  
  <p>I have placed the shortcode <code>[woocommerce_recently_viewed_products]</code></p>
  
  <p>and have generated the shortcode using the following script:</p>
  
  <pre><code>function rc_woocommerce_recently_viewed_products( $atts, $content = null ) {
  
  // Get shortcode parameters
  extract(shortcode_atts(array(
      "per_page" =&gt; '5'
  ), $atts));
  
  // Get WooCommerce Global
  global $woocommerce;
  
  // Get recently viewed product cookies data
  $viewed_products = ! empty( $_COOKIE['woocommerce_recently_viewed'] ) ? (array) explode( '|', $_COOKIE['woocommerce_recently_viewed'] ) : array();
  $viewed_products = array_filter( array_map( 'absint', $viewed_products ) );
  
  // If no data, quit
  if ( empty( $viewed_products ) )
      return __( 'You have not viewed any product yet!', 'rc_wc_rvp' );
  
  // Create the object
  ob_start();
  
  wc_setcookie( 'woocommerce_recently_viewed', implode( '|', $viewed_products ) );
  }
  
  // Get products per page
  if( !isset( $per_page ) ? $number = 4 : $number = $per_page )
  
  // Create query arguments array
  $query_args = array(
                  'posts_per_page' =&gt; $number, 
                  'no_found_rows'  =&gt; 1, 
                  'post_status'    =&gt; 'publish', 
                  'post_type'      =&gt; 'product', 
                  'post__in'       =&gt; $viewed_products, 
                  'orderby'        =&gt; 'rand'
                  );
  
  // Add meta_query to query args
  $query_args['meta_query'] = array();
  
  // Check products stock status
  $query_args['meta_query'][] = $woocommerce-&gt;query-&gt;stock_status_meta_query();
  
  // Create a new query
  $r = new WP_Query($query_args);
  
  // If query return results
  if ( $r-&gt;have_posts() ) {
  
      $content = '&lt;ul class="rc_wc_rvp_product_list_widget"&gt;';
  
      // Start the loop
      while ( $r-&gt;have_posts()) {
          $r-&gt;the_post();
          global $product;
  
          $content .= '&lt;li&gt;
              &lt;a href="' . get_permalink() . '"&gt;
                  ' . ( has_post_thumbnail() ? get_the_post_thumbnail( $r-&gt;post-&gt;ID, 'shop_thumbnail' ) : woocommerce_placeholder_img( 'shop_thumbnail' ) ) . ' ' . get_the_title() . '
              &lt;/a&gt; ' . $product-&gt;get_price_html() . '
          &lt;/li&gt;';
      }
  
      $content .= '&lt;/ul&gt;';
  
  }
  
  // Get clean object
  $content .= ob_get_clean();
  
  // Return whole content
  return $content;
  }
  
  // Register the shortcode
  add_shortcode("woocommerce_recently_viewed_products", 
  "rc_woocommerce_recently_viewed_products");
  </code></pre>
  
  <p>Everything seems to have registered. However,when I test this myself. I view a few products, go back to the homepage where the shortcode is registered and I see the text </p>
  
  <blockquote>
    <p>You have not viewed any product yet!</p>
  </blockquote>
  
  <p>I can not figure out what might be missing in order to register and show the products which I or a potential customer may have viewed.</p>