If you have a WooCommerce online store, there are often many doubts about how to apply a correct caching strategy for the store to offer fast and efficient navigation, while not generating problems when updating products in the cart or making payments.
So I have long wanted to explain how to configure the cache in a WooCommerce online store, to avoid doubts and annoyances, and that is what we are going to see in this guide, which I hope, at the same time, will clarify doubts and avoid surprises.
Table of Contents
What is cache?
Caching is when you “save” a website to allow the site to load faster for visitors than if each element of the site had to be reloaded each visit.
The resources of a cached website are already loaded and so can be served faster than if the website had to “build” the page each time there is a new visit.
How does caching affect WooCommerce?
Caching plugins like WP Rocket don’t generate cache for logged in users by default, so normally there won’t be any problems caused by caching (except for what we will see below), but what about users who are not logged in?
I am mainly referring to new customers who have not yet placed an order and have not logged in to their account. How do these offline users see your online store?
A badly applied cache to an online store could cause some of these problems…
- Customers seeing other people’s details.
- Customers who see products in their cart that they have not added themselves.
- Customers who see another customer’s address when they go to checkout.
- Customers who when going to the cart do not see the products they have added but other products.
- … etc.
If you have this kind of problems, or similar, then you have not configured correctly the cache for WooCommerce.
Let’s fix it.
Don’t think it’s trivial, because if you have this kind of problem your customers will not trust your online store to make purchases, and you may even be incurring in disclosure of sensitive data of other customers without knowing it.
As an online store owner it is your responsibility to ensure that your store is secure, complies with all privacy regulations, and offers a safe and correct shopping experience.
Do I have to configure the cache specifically for WooCommerce?
When you cache your web content it is no longer dynamic, the content is stored and then served to subsequent visitors the same way every time.
This means that if your checkout page is cached it will never show each customer their correct shopping cart, it will show what they have stored, it would not be updated on each visit.
Of course, WooCommerce is dynamic, and you have to make sure that the pages that have to be dynamic are excluded from the cache.
How to configure the cache for WooCommerce?
If you use any caching plugin, such as W3 Total Cache, WP Super Cache or Cache Enabler you have to make sure that caching is being applied correctly to WooCommerce by performing some checks.
Exclude WooCommerce pages from the cache.
Since WooCommerce 1.4.2, WooCommerce automatically sets up the DONOTCACHEPAGE constant, which technically means that you don’t need to exclude the pages it creates from your caching system.
However, if your caching plugin does not support the DONOTCACHEPAGE constant you will need to exclude dynamic pages from WooCommerce.
To find out if a plugin is compatible with DONOTCACHEPAGE you don’t usually have to do a lot of digging, it is usually specified in its documentation.
And, if you have doubts, in most caching plugins it is quite easy to exclude pages from the cache, just go to their settings and configure the following pages to be excluded from the cache:
- Cart
- Checkout
- My account
- Store (optional, as it is a loop most of the cache plugins update it when creating a new product)
As you can see, the pages in this list are the main dynamic pages that WooCommerce creates. They are pages whose content will vary based on the actions the visitor performs with your products (add to cart, go to checkout, checkout, etc.).
Most plugins will offer a setting to exclude content from the cache, for example:

But it may not be necessary, first check if by default you are not caching WooCommerce pages.
Note: If you use SG Optimizer or WP Rocket you have nothing to worry about, both plugins automatically exclude WooCommerce pages by default.
How do I check if WooCommerce dynamic pages are excluded from the cache?
If you use the SG Optimizer plugin it’s simple, you have a tool to check it in the plugin settings.
If you use another cache plugin then you will have to look at the response headers of the pages to test.

In the above case you can check that the page is not in the cache.
Note: If you have problems with clients resetting the password and access try excluding my-account.php from your plugin cache.
Exclude WooCommerce sessions from the cache.
Depending on the caching plugin you are using, you may need to exclude WooCommerce sessions.
Most generic plugins, such as W3 Total Cache, WP Rocket, Cache Enabler, etc., do not cache the database, but there are server caches that do, so in that case you would have to exclude WooCommerce sessions.
You would simply have to exclude the string “_wc_session_
” from the cache.
Exclude WooCommerce cookies from the cache.
Have you ever added items to the cart, emptied the cart, reloaded the page and suddenly the items in the cart reappear?
This, besides being confusing for your customers, can become a big problem, because you could have duplicate items in the orders, for example, causing major conflicts with your users.
Fortunately it is very easy to correct this problem, simply by excluding WooCommerce cookies from the cache.
There are currently 5 WooCommerce cookies that you can exclude from the cache:
woocommerce_cart_hash
– Determines when the cart refreshes or reloads. Fundamental to exclude from the cache to ensure the cart always reflects the correct items.woocommerce_items_in_cart
– Another cookie that helps WooCommerce determine that the correct data is in the cart. You should also exclude it from the cache to ensure the cart displays properly.wp_woocommerce_session
– This is your visitor’s unique code cookie, assigned to each customer, that helps WooCommerce find each customer’s cart in the database. Again, as you will understand, it is essential to exclude it from the cache.woocommerce_recently_viewed
– This cookie is the one that powers the recently viewed items widget. If you use it, it would be wise to exclude it from the cache.store_notice[notice id]
– This is the cookie that stores whether or not the customer has dismissed the store notice. If you use it, exclude it from the cache, so that you are not bothering your visitors on every page showing the notice that they have already dismissed.
Again, in your cache plugin you will usually find a field in which to add strings to exclude.
What about CloudFlare’s cache?
Well, nothing happens, because CloudFlare cache is also compatible and does not cache WooCommerce dynamic pages.
Do I minimize or not minimize HTML, CSS and JavaScript in WooCommerce?
The official WooCommerce documentation recommends not to minimize JavaScript. However, I recommend you to try minimizing JavaScript, because you would be wasting a great optimization potential of your online store.
If everything works, well, it works.
A sure way to minimize JavaScript without problems with your online store is to exclude WooCommerce scripts from the minimization, something that the best caching plugins, such as SG Optimizer, will allow you to do.

How to test that your WooCommerce store is working properly after configuring the cache?
Once you have configured the cache of your WooCommerce online store, it’s time to test to see if everything works.
What do we do? Well, this would be a reasonable list:
- Check that your product page (store) loads well and displays all products well.
- Check that your product taxonomy pages load well and show the correct products.
- Make a purchase on your website, offline, as a guest. Make sure that products are correctly added to the cart, that the checkout works properly and that all sale details are displayed and saved correctly.
- Make a purchase on your website, as a registered and logged in user. Make sure that the products are correctly added to the cart, that the payment works correctly and that all the details of the sale are displayed and saved correctly.
- Check that your account page reflects your purchases and purchase details correctly.
- Create a coupon and try using it both in the cart and on the checkout page, and check that the quantities in the cart and checkout are updated correctly.
- Try resetting your password and make sure the process is successful.
Does everything in the list work? Great, you’re done.
Still having problems? Go to the next step…
What to do when the cache keeps generating problems in your WooCommerce store?
The most important thing is not to rush or panic. Even if you are worried about problems in your online store with the cache, don’t panic, everything can be fixed, always.
To begin with, if you have also activated the minimized and combined of your files (HTML, CSS, JS), deactivate these options, empty the cache, delete the data stored in the browser, and test again in your online store, connected and disconnected. I always have installed and at hand the TOR browser, which does not save cache, cookies, anything, it is the best private browser.
Everything is working again? Then re-activate the minimized files, but without combining them, and check again your online store. If everything is fine you know that it was the merging that was causing problems, and if it does not work then it is the minimized files, all or some of them.
Still having problems? Then you will have to hire a WordPress and WooCommerce consultant you trust.
Which caching plugins work best with WooCommerce?
In my experience with my own Ecommerce and WordPress maintenance clients, the cache plugins with which you never have problems in WooCommerce online stores are SG Optimizer if you have the website hosted on SiteGround, or WP-Rocket for any other hosting.
To summarize…
If I had to summarize this guide on caching for WooCommerce in a few points I would say…
- By default WooCommerce does not cache dynamic pages, so normally everything will work fine and you won’t have to do anything.
- Use a good caching plugin, compatible with WooCommerce (DONOTCACHEPAGE) and optimize the site to your liking without worries.
- In case of problems, check this guide, that’s why I wrote it, isn’t it?
Let me know in the comments if you have learned or if it has been useful.