Posted on

Boost Your E-Commerce Sales with WooCommerce Recent Viewed Products Feature

Screenshot from 2023 04 16 17 21 25


Boost Your E-Commerce Sales with WooCommerce Recent Viewed Products Feature

As an online store owner, you are always looking for ways to enhance the shopping experience for your customers and increase your sales. One powerful tool that can help you achieve these goals is the WooCommerce Recent Viewed Products feature. In this blog post, we will explore how this feature can benefit your e-commerce store and provide step-by-step instructions on how to implement it.

Why is the WooCommerce Recent Viewed Products Feature Important?

The WooCommerce Recent Viewed Products feature allows your customers to easily track and revisit products they have previously viewed on your online store. It creates a sense of personalized shopping experience, making it convenient for customers to find and purchase products they are interested in. Here are some key reasons why this feature is important for your e-commerce store:

  1. Increased Engagement: By showing customers the products they have recently viewed, you can keep them engaged with your store and encourage them to spend more time browsing through your product offerings.
  2. Easy Product Recall: Customers may browse your store and view multiple products before making a purchase decision. The Recent Viewed Products feature allows them to quickly recall the products they have previously viewed, reducing the need to search for them again.
  3. Improved Conversion Rates: When customers can easily find and revisit products they are interested in, it can lead to higher conversion rates as it streamlines the purchase process.
  4. Personalized Shopping Experience: The Recent Viewed Products feature adds a personal touch to the shopping experience by showing customers the products they have shown interest in. This can enhance customer satisfaction and loyalty.

Implementing the WooCommerce Recent Viewed Products Feature

Implementing the WooCommerce Recent Viewed Products feature is relatively simple, and it can be done with the help of custom code. Here is a step-by-step guide on how to implement this feature on your WooCommerce store:

  • Step 1 – Add This Snipt in the functions.php
function custom_track_product_view() {
  if ( ! is_singular( 'product' ) ) {
      return;
  }

  global $post;

  if ( empty( $_COOKIE['woocommerce_recently_viewed'] ) )
      $viewed_products = array();
  else
      $viewed_products = (array) explode( '|', $_COOKIE['woocommerce_recently_viewed'] );

  if ( ! in_array( $post->ID, $viewed_products ) ) {
      $viewed_products[] = $post->ID;
  }

  if ( sizeof( $viewed_products ) > 4 ) {
      array_shift( $viewed_products );
  }

  // Store for session only
  wc_setcookie( 'woocommerce_recently_viewed', implode( '|', $viewed_products ) );
}

add_action( 'template_redirect', 'custom_track_product_view', 20 );
  • Step 2 – Create Shortcoder
function woo_recently_viewed_shortcode() {
 
   $viewed_products = ! empty( $_COOKIE['woocommerce_recently_viewed'] ) ? (array) explode( '|', wp_unslash( $_COOKIE['woocommerce_recently_viewed'] ) ) : array();
   $viewed_products = array_reverse( array_filter( array_map( 'absint', $viewed_products ) ) );
 
   if ( empty( $viewed_products ) ) return;
    
   $title = '<section class="title-block pt-50">
            <div class="container">
              <h2>Recently Viewed Products</h2>
            </div>
          </section>';
   $product_ids = implode( ",", $viewed_products );
   //  print_r($product_ids);
 
   return $title . do_shortcode("[products ids='$product_ids']");
   
}
add_shortcode( 'recently_viewed_products', 'woo_recently_viewed_shortcode' );
  • Step 3 – Add Shortcode – [recently_viewed_products]

Customization Options for the WooCommerce Recent Viewed Products Feature

If you prefer to implement the Recent Viewed Products feature using custom code, WooCommerce provides hooks and functions that allow you to customize its behavior. Here are some customization options you can consider:

  1. Change the Number of Products Displayed: You can modify the number of products displayed in the Recent Viewed Products widget by changing the plugin settings or customizing the code.
  2. Customize the Widget Layout: You can customize the layout and design of the Recent Viewed Products widget by modifying the CSS code or using custom templates.
  3. Add Additional Information: You can customize the widget to display additional information about the viewed products, such as product images, prices, or ratings, to provide more context to customers.
  4. Implement Exclusions: You can exclude specific products or product categories from being displayed in the Recent Viewed Products widget by customizing the code.

Add directly in the template file code snippet.

<?php 
global $woocommerce;


 ?>
	<section class="title-block pt-50">
		<div class="container">
			<h2>Recently viewed products</h2>
		</div>
	</section>
	<section id="occassions-product-5" class="recentview layout occassions-products">
		<div class="container ">
			<div class="woocommerce columns-4">
					<?php 
				// 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!', 'ecoSoft' );
				
					// Create the object
					ob_start();

					if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
					global $post, $woocommerce, $product;
					$wp_query = new WP_Query( array(
										'posts_per_page' => 5, 
										'no_found_rows'  => 1, 
										'post_status'    => 'publish', 
										'post_type'      => 'product', 
										'post__in'       => $viewed_products,
										
					
					)); ?>
					<ul class="products columns-4 featured-col">
						<?php while ($wp_query->have_posts()) : $wp_query->the_post(); global  $post, $product;?>	
						<li class="product">
							<span class="eggless"></span>
							<a href="<?php echo esc_url( get_permalink( $product->id ) ); ?>" class="woocommerce-LoopProduct-link woocommerce-loop-product__link">
							<?php echo $product->get_image(); ?>
								<p class="woocommerce-loop-product__title text-dark">
								<?php echo $product->get_title(); ?>		</p>
								<span class="price"><?php echo $product->get_price_html(); ?></span>
							
						</a> </li>
														
						<?php
						endwhile;
						
						wp_reset_query();
						wp_reset_postdata(); ?>
					</ul>
			</div>
		</div>
	</section>
<?php  
wp_reset_postdata();
Screenshot from 2023 04 16 17 21 25

Ref. Url: https://yummycake.ddev.site/product/floral-yummy-cake/

In conclusion, implementing the WooCommerce Recent Viewed Products feature on your e-commerce store can greatly benefit your business by increasing engagement, improving conversion rates, and providing a personalized shopping experience for your customers. Whether you choose to use a plugin or custom code, it’s a relatively simple and effective way to enhance your online store’s functionality and boost your sales.

So, don’t miss out on this powerful tool for improving your e-commerce business! Take action now and start implementing the WooCommerce Recent Viewed Products feature on your store. Utilize WooCommerce hooks and functions to tailor the feature to your specific needs. Your customers will appreciate the convenience and personalization, and you’ll see the positive impact on your sales and customer satisfaction.

Take the first step towards maximizing your e-commerce success with the WooCommerce Recent Viewed Products feature. Don’t wait, implement it today and watch your sales soar!

Call To Action

Get Started with WooCommerce Recent Viewed Products Today and Boost Your Sales! Install a plugin or customize the code to implement this powerful feature on your e-commerce store. Don’t miss out on the opportunity to provide a personalized shopping experience for your customers and increase your conversions. Take action now and watch your sales grow! Click here to learn more.