WooCommerce缓存教程 – 如何防止缓存破坏你的WooCommerce网站?插图

In previous articles, we discussed how to speed up your WordPress site and studied various forms of caching.

, however, like dynamic e-commerce sites that use WooCommerce, often face major challenges in making the cache work.

in this guide, we will show you how to set up any WordPress caching plug-ins for WooCommerce, what to do if something goes wrong, and how to test whether your changes are valid.

  1. what is caching? How does
  2. caching affect WooCommerce? Why does
  3. need to explicitly configure caching for WooCommerce? How does
  4. set the cache for WooCommerce?
  5. which cache plug-ins work best for WooCommerce?
  6. Summary

what is caching?

simply says that caching is about “saving” the site so that the end user can load all aspects of the site faster than each time. The assets of the

cache site have been loaded, so you can get services faster than the site loads and “builds” pages every time it is requested. How does

caching affect WooCommerce?

caching plug-ins like WP Rocket don’t cache logged-in users by default, but what happens if you cache logged-in users and your site doesn’t have the necessary settings?

, have you ever been in a situation like this? Do

  • customers see other customers’ account information?
  • customers have mysterious items in their shopping carts, but they swear they didn’t add them?
  • customers complain about seeing someone else’s address at checkout?

, then your cache settings for WooCommerce are incorrect! Don’t worry, we’ll discuss how to solve the problem later.

, but it is very important to understand the hidden dangers.

  • customers lose trust.
    Potential data protection problems

as a shopkeeper, you are responsible for ensuring that your store is safe and complies with all legal regulations. Why does

need to explicitly configure caching for WooCommerce?

when you cache content on a site, it is no longer dynamic, the content is saved and then made available to your visitors in the same way each time. This means that if you cache your checkout page, it will never show customers their correct shopping cart.

WooCommerce is dynamic, and you need to make sure that dynamic pages are excluded from the buffer. How does

set the cache for WooCommerce?

if you are using popular cache plug-ins such as W3 Total Cache, WP Super Cache or WP Fastest Cache, you need to do the following:

Step 1: exclude WooCommerce pages from your cache plug-ins

in most WooCommerce cache plug-ins, excluding pages is quite straightforward, just go to the cache plug-in settings and look for exclusion options And set the following page to exclude:

  • shopping cart
  • payment page
  • my account
  • product

is the main dynamic page provided by WooCommerce, and its content will change depending on who is watching this page.

if you are using WP Rocket, good news! You don’t need to do anything (WP Rocket doesn’t include all WooCommerce pages by default)! Nothing needs to be done (WP Rocket excludes all WooCommerce pages by default).

in addition, since WooCommerce 1.4.2, WooCommerce has set the DONOTCACHEPAGE constant, which means that technically you don’t need to exclude these pages from your caching scheme.

, however, if your cache plug-in does not support DONOTCACHEPAGE constants, then you still need to exclude it. Most caching plug-ins specifically mention WooCommerce compatibility, if they have one.

if you have problems with customers resetting passwords and login, you can try to exclude my-account.php from your cache plugin.

Step 2: the specific step of excluding WooCommerce sessions from the cache

depends on the cache plug-in you use, most of which do not include database caching. However, there are some where you need to exclude “_ wc_session_” from the cache in these plug-ins.

in W3 Total Cache, which is done automatically, can be found through your wp-admin & gt; Performance & gt; Database Cache:

WooCommerce缓存教程 – 如何防止缓存破坏你的WooCommerce网站?插图1

Step 3: excluding WooCommerce Cookies from the cache

have you ever had this experience: you added some items to the shopping cart to test the cache, you emptied the shopping cart, refreshed the page, bang! Are your items still in the shopping cart?

this not only makes your visitors worried and confused, but also leads to mistrust of your site, and in the end, potential customers will not come back. Fortunately for

, there is an easy way to solve this problem by excluding WooCommerce cookies’s cache.

currently, there are four WooCommerce cookies that should be excluded from the cache:

  • Woocommerce_cart_hash-handles helpers that determine when the shopping cart is updated or refreshed. Must be excluded from the cache to ensure that the shopping cart reflects the correct items.
  • Woocommerce_items_in_cart-another helper that helps WooCommerce determine the correct data in the shopping cart. Must be excluded from the cache to ensure that the shopping cart reflects the correct items.
  • Wp_woocommerce_session-this cookie contains the unique code for the visitor, assigned to each customer, and helps WooCommerce find shopping cart data for each customer in the database. Again, you must exclude this from your shopping cart.
  • Woocommerce_recently_viewed-the recently browsed gadget, again, you must exclude this cookies from the cache to ensure that the recently viewed gadget is displayed correctly for each visitor. Is

interested in learning more about cookie and how they are used in WooCommerce? Please check the official guide.

Step 4: do you want to minimize it? This is a problem.

WooCommerce himself advises against minimizing JavaScript. However, if you don’t minimize it, you’ll lose potential performance improvements.

instead, we recommend that JavaScript is still minimized, but WooCommerce scripts are not included in the minimization process.

WP Rocket has a good guide on how to find the right script to rule out minimization.

Step 5: how do I test if the WooCommerce store works after storage

once you’re satisfied with your cache configuration, it’s time to test if your WooCommerce store is still working, but how do you do that?

you need to do the following:

  • tests whether your product page loads and displays the correct product.
  • tests whether your category page loads and displays the correct product.
  • makes purchases on your website and logs in as guests. Make sure the checkout is normal, the payment is successful, and the details shown are correct.
  • logs in as a customer on your website and makes the purchase. Make sure the checkout is normal, the payment is smooth, and the details shown are correct.
  • Create a coupon and try to use it at checkout, making sure that the coupon is applied, the amount in the shopping cart and the price paid are correct.
  • tries to reset the password to make sure everything is all right.

all the above work? Great! Then there is nothing else to do. Is there a problem? Proceed to step 6.

Step 6: what to do when the cache still destroys the WooCommerce website? The most important part of

is not to panic! This can be scary when your website breaks down, but don’t worry. Any problem can be solved.

first, if you have enabled minimize and merge files (in some plug-ins, this is called concatenation). Disable these options, clear your browser cache, and then try your site in an invisible browser session.

, is everything all right now? Try to enable minimization without merging files and test your site again; if it breaks again, you know that merging files will damage your site if it still doesn’t work. You have followed our advice in this article, and it may be time to find a developer.

if you really need expert help, you can try to contact us (paid for, of course, and not cheap).

which cache plug-ins work best for WooCommerce?

in our experience, the best caching plug-in for WooCommerce is WP Rocket;, which works right out of the box and does not require additional configuration. If for any reason you are in trouble, they have a team of first-class cache support experts waiting to help you.

if you are looking for a free alternative, in our own tests, WP Fastest Cache and W3 Total Cache have proved to be good free alternatives that work well with minimal setup hassle.

summary

setting up cached WooCommerce is not necessarily complicated. I hope this guide is helpful to you! Are there any other tips we haven’t included here? Please tell us in the comments below.

Disclaimer: All articles on this website, unless otherwise specified or marked, are original and published on this website. Any individual or organization is prohibited from copying, stealing, collecting, or publishing the content of this site to any website, book, or other media platform without the consent of this site. If the content on this website infringes on the legitimate rights and interests of the original author, you can contact us for assistance.