Making WP Rocket work with WooCommerce recently viewed products widget

The  WooCommerce Recently Viewed Products widget displays a list of the products a visitor/customer previously viewed on your shop.

With the default WP Rocket settings, the list will be cached during the first visit, and the same will be shown to all visitors, rendering the widget useless and even returning wrong results.

With the mu-plugin below, you'll be able to use the widget with caching without any issue:

 * Plugin Name: Dynamic Cache WooCommerce recently viewed products
 * Description: Create a specific cache for each value of woocommerce_recently_viewed cookie
 * Author:      WP Rocket team
 * License:     GNU General Public License v3 or later
 * License URI:

// Basic security, prevents file from being loaded directly.
defined( 'ABSPATH' ) or die( 'Cheatin&#8217; uh?' );

add_filter( 'rocket_htaccess_mod_rewrite' , '__return_false' );
add_filter( 'rocket_cache_dynamic_cookies', '__rocket_dynamic_cache_wc_recently_viewed_products' );

function __rocket_dynamic_cache_wc_recently_viewed_products( $dynamic_cookies ) {
	$dynamic_cookies[] = 'yith_wrvp_list_0';

    return $dynamic_cookies;

If you don't know how to create a MU-plugin, please check out our doc:  How to Make a Custom (MU) Plugin

For Logged In Users! Remember to disable User cache in WP Rocket when using the Recently Viewed Products plugin. For logged in users, the dynamic cookie used by the plugin is appended with the user id of the current user. For example, if the user id is 10, the cookie name will be yith_wrvp_list_10. Since this new cookie isn't mentioned in the exclude list for WP Rocket, the recent product list will still be cached.