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
- Cart, Checkout and My Account must stay dynamic because they show one customer's data
- The wp_woocommerce_session_ cookie lasts 2 days and links a visitor to their cart in the database
- WooCommerce recommends avoiding JavaScript minification when you use WP Rocket
- W3 Total Cache needs mfunc added to Ignored comment stems in its Minify settings
| Cookie | Lasts | What it does |
|---|---|---|
| woocommerce_cart_hash | Session | Tells WooCommerce when cart contents change |
| woocommerce_items_in_cart | Session | Tells WooCommerce when cart contents change |
| wp_woocommerce_session_ | 2 days | Holds the code that finds this customer's cart in the database |
| woocommerce_recently_viewed | Session | Powers the Recently Viewed Products widget |
| store_notice[notice id] | Session | Lets 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:
- The cart shows empty, or shows items the shopper already removed.
- The mini-cart count in the header does not update.
- Checkout fails with a session or security error.
- Password reset sends people back to the login screen in a loop.
All of them trace back to caching something that belongs to one customer.
Step by step: set up caching for WooCommerce
- Check which pages are your cart, checkout and account pages under WooCommerce > Settings > Advanced > Page setup, and note their URLs.
- In your cache plugin, exclude those three URLs and everything under them (for example /my-account/ and its endpoints) from the page cache.
- 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.
- Keep caching off for logged-in users unless your plugin offers a separate private cache for them.
- If you use database or object caching, exclude _wc_session_ entries, as WooCommerce suggests.
- Do not cache URLs containing ?add-to-cart=.
- Turn on CSS and JavaScript optimization last, one setting at a time.
- 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.
Settings for popular cache plugins
- WP Super Cache: WooCommerce tells it not to cache Cart, Checkout and My Account by default. Check the cookie exclusions and test.
- WP Rocket: WooCommerce's docs ask you to confirm the three pages are not cached in WP Rocket's settings and to avoid JavaScript file minification.
- W3 Total Cache: add mfunc to Ignored comment stems under Minify, and exclude the pages and cookies by hand.
- LiteSpeed Cache: it lists WooCommerce support and lets you exclude by URI and cookie. Its page cache only runs on LiteSpeed servers.
- Varnish or host cache: ask your host to pass cart, my-account, checkout and add-to-cart requests to WordPress. WooCommerce's docs include a sample Varnish rule.
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
- WooCommerce developer docs: How to configure caching plugins
- WordPress.org: WP Super Cache
- WordPress.org: LiteSpeed Cache
- WordPress.org: W3 Total Cache