Dealing with Cache

Issue #

Caching plugins and plugins that use cache in order to function cause the menu cart to fail to update. This may cause issues including different displaying on mobile, seeing old displays of the cart after adjusting it and visiting a new page, etc.

Known conflicting plugins #

  • WP Rocket
  • Bricks by FlyingPress
  • Litespeed caching
  • W3 Total Cache

Solution #

Refresh cart fragments #

This method gives us something to reactivate the cart fragments, so that they will output as normal.

Use this code snippet:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
add_action( 'wp_enqueue_scripts', 'wpo_enqueue_wc_cart_fragments' );
function wpo_enqueue_wc_cart_fragments() {
wp_enqueue_script( 'wc-cart-fragments' );
}
add_action( 'wp_enqueue_scripts', 'wpo_enqueue_wc_cart_fragments' ); function wpo_enqueue_wc_cart_fragments() { wp_enqueue_script( 'wc-cart-fragments' ); }
add_action( 'wp_enqueue_scripts', 'wpo_enqueue_wc_cart_fragments' );
function wpo_enqueue_wc_cart_fragments() {   
	wp_enqueue_script( 'wc-cart-fragments' ); 
}

If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use code snippets

Afterwards, open a new tab or a new page and from there, test the menu cart.