THTheme

How to configure cache plugins with WooCommerce

To cache a WooCommerce store safely, exclude the Cart, Checkout and My Account pages from the page cache and skip caching for visitors who carry the woocommerce_items_in_cart, woocommerce_cart_hash or wp_woocommerce_session_ cookies. WP Super Cache gets the page exclusions from WooCommerce automatically; most other caches need you to set them. Finish by running a full test order in a private browser window.

Updated · By THTheme Editorial Team

Key facts

WooCommerce cookies to exclude from caching (from WooCommerce's docs)
CookieLastsWhat it does
woocommerce_cart_hashSessionTells WooCommerce when cart contents change
woocommerce_items_in_cartSessionTells WooCommerce when cart contents change
wp_woocommerce_session_2 daysHolds the code that finds this customer's cart in the database
woocommerce_recently_viewedSessionPowers the Recently Viewed Products widget
store_notice[notice id]SessionLets a customer dismiss the store notice

Why a store needs its own cache rules

A page cache serves one saved copy of a page to many visitors. That is perfect for a product page and wrong for a cart. When a cart or account page gets cached, you see problems like these:

All of them trace back to caching something that belongs to one customer.

Step by step: set up caching for WooCommerce

  1. Check which pages are your cart, checkout and account pages under WooCommerce > Settings > Advanced > Page setup, and note their URLs.
  2. In your cache plugin, exclude those three URLs and everything under them (for example /my-account/ and its endpoints) from the page cache.
  3. Add the cart and session cookies in the table above to the plugin's cookie exclusions, so a visitor with items in the cart always gets a fresh page.
  4. Keep caching off for logged-in users unless your plugin offers a separate private cache for them.
  5. If you use database or object caching, exclude _wc_session_ entries, as WooCommerce suggests.
  6. Do not cache URLs containing ?add-to-cart=.
  7. Turn on CSS and JavaScript optimization last, one setting at a time.
  8. In a private window, add a product, change the quantity, check out, create an account and reset its password. Then clear the cache and repeat once.

Not sure which plugin to use? See the caching plugin roundup.

Troubleshooting a cached store

If customers report a password reset loop, the My Account page is almost always cached at the server, outside your plugin. Ask your host to exclude it. If the header cart count is stale, check that your theme's cart fragments script is not delayed or combined by your optimization settings. If only some visitors see problems, a CDN may be caching HTML: set it to bypass cache when the WooCommerce cookies are present. For general speed work beyond caching, read the WordPress speed guide.

FAQ

Should I cache WooCommerce product pages?

Yes. Product, category and shop pages are the same for every visitor and benefit most from caching. Only cart, checkout, account pages and visitors with cart cookies need to skip the cache.

Does WP Rocket work with WooCommerce?

Yes. WooCommerce says it is fully compatible, as long as Cart, Checkout and My Account are not cached and JavaScript file minification is avoided.

Why is my WooCommerce cart empty after adding a product?

Usually the cart page or the cart cookies are being cached. Exclude the cart page and the woocommerce_items_in_cart and wp_woocommerce_session_ cookies, then clear all caches.

Why is my password reset stuck in a loop?

The My Account page is being cached, often by the host's server cache. Ask the host to exclude it from caching.

Sources