WpW: Fixing LSCache+WooCommerce Conflicts

Written by

in

Welcome to another installment of WordPress Wednesday!

Do you use WooCommerce? Have you tried to use LiteSpeed Cache only to find that your cart was not updating correctly? Today we’re going to explore a configuration tweak that fixes an incompatibility between LiteSpeed Cache and some WooCommerce themes.

A quick note before we begin: We went in-depth discussing the benefits of adding LSCache to your WooCommerce setup last week. You can check that out here, if you missed it.

WooCommerce and LiteSpeed work together quite well right out of the box in most cases, however there are some situations where the addition of LSCache causes the shopping cart to be updated incorrectly. This is easily fixable.

LiteSpeed Cache can give your shop a considerable performance boost, and as such is a useful addition to your WordPress arsenal. It’s well worth investing a few minutes to fix this little hiccup, if your site is affected by it.

Some WooCommerce themes (Storefront, Shop Isle and other themes with an ajax cart, for example) are fully-compatible with LSCache and there is no need for any special consideration. However, for other themes (like E-Commerce), LiteSpeed will need a quick and easy configuration tweak.

First, let’s find out if your theme has an issue.

  1. On a non-logged-in browser, with the cache active, enable your browser’s code inspector, and visit your shop’s home page. Then, visit a product page. Both of these pages should be newly-cached now.
  2. To verify that a page is cached, using the inspector, navigate to the Network tab, click on the page’s URL in the list (reload the page, if you don’t see it), and then look at the response headers. If you see X-LiteSpeed-Cache: hit, then the currently-loaded page was served from cache.
  3. Perform this check on both pages.
  4. Add the product from the product page to your cart.
  5. Visit the shop home page again, but do so by clicking a link to it from the product page (in other words, don’t use the Back button).
  6. Check to see if the home page is still cached (it should be) and that the cart contains the product you just added to it (it should).
  7. If you’re seeing something different, then you’ll need to update your do-not-cache cookie list.

Here’s how to update your do-not-cache cookie list:

In your WordPress Admin, go to LiteSpeed Cache > Settings > Do Not Cache Rules.

Under Cookie List, enter woocommerce_items_in_cart, scroll down and press Save Changes.

If you’d like to verify that this is working, repeat steps 1-6 above.  Unlike before, we should now see that the home page is still cached and the cart is properly updated.

Congratulations!

You can see that WooCommerce and LiteSpeed Cache are usually a great team right from Day One, but if you’re observing quirky behavior, it’s quite simple to configure LSCache to make an allowance for it.

If your WooCommerce store isn’t taking advantage of LiteSpeed Cache’s performance-boosting power, why not? Online shoppers have a notorious lack of patience, and slow sites lose customers. LiteSpeed can keep your load times low and your customers smiling. Don’t take our word for it, though. Check out these awesome user reviews!

Have any questions about this? Have some of your own ideas for future WordPress Wednesday topics? Leave us a comment!

Don’t forget to meet us back here next week for the next installment. In the meantime, here are a few other things you can do:

Comments

17 responses to “WpW: Fixing LSCache+WooCommerce Conflicts”

  1. Ruben hestholm Avatar

    Hi. I have problem with my checkout page not updating shipping information. Can this be fixed using the method described in this post?

    1. Lisa Clarke Avatar
      Lisa Clarke

      Hi, Ruben. It’s hard to say without knowing more about your site’s setup. You can try the solution in this post – it couldn’t hurt. If that doesn’t fix it, you can create a ticket through our client area or by sending email to support@litespeedtech.com, and we’ll be happy to help you figure it out.

  2. David Bennett Avatar

    Hi,
    As of today – 29 November 2018 – is the recommendation about cookies still good advice?

    I have not actually suffered any problems, as far as I am aware, so perhaps my theme is compatible – but… is it perhaps a good idea to add the ‘woocommerce_items_in_cart’ just in case? Or can it cause more harm than good if it is not needed?

    1. Lisa Clarke Avatar
      Lisa Clarke

      Hi, David.

      it depends on what theme you are using. The themes with the Ajax carts work fine without any adjustment. Adding the cookie to the Do Not Cache Cookies list should really be considered a last resort. Any time you tell LSCWP not to cache a cookie, then any page that is visited while the cookie is detected will not be cached. That slows down your site dramatically, so only use that option if you have no other choice.

      You can run through those steps above to verify that your theme works as-is. If it doesn’t, we have introduced ESI since this blog post was written. You can learn more about ESI here, but essentially, with ESI enabled, your WooCommerce cart automatically becomes a privately-cached ESI block, and it can appear on any page without affecting how that page is cached.

      We’re working on a new blog post to talk a bit more about WooCommerce and ESI, so keep an eye open for that, if it turns out your theme doesn’t have an ajax cart!

      Hope this helps!
      Lisa

  3. Jordy Avatar
    Jordy

    Hi,

    I have litespeed up and running with my woocommerce and wp job manager website.

    However, woocommerce gives the option to set the user location. Normally this is done with geolocation, but it also gives the option to do this with page caching.

    Is this extra page caching for the geolocation necessary, or is this already done in litespeed and can I leave it in woocommerce to the normal geolocation option?

    Thanks,
    Jordy

    1. Lisa Clarke Avatar
      Lisa Clarke

      Hi, Jordy.

      I was unfamiliar with this option, but I just read a bit about how it works, and based on that, I recommend that you enable Geolocate (with page caching support). Essentially what that option does is it uses an Ajax call to determine if the current user is from the same place as the previously-cached location. If the user is from someplace different, a query string will be added to the page URL, which will cause a new version of the page to be cached with the user’s correct location. That is a solution that should work with any page-caching plugin including LiteSpeed.

      I suspect there are other ways to set up a slightly more efficient LiteSpeed-based cache vary for geolocation purposes, and I can look into that for you, if you want. Just let me know. But the absolute easiest way to set this up is to just use that WooCommerce option.

      1. Jordy Avatar
        Jordy

        Hi Lisa,

        Thanks for your detailed reply! I would definetily be interested in a different solution with litespeed, as the solution offered by Woocommerce adds an extra string to all url’s of the website, which doesnt look very nice.

        Best regards,
        Jordy

        1. Lisa Clarke Avatar
          Lisa Clarke

          Ok, well, it involves using “cache vary” functionality in order to cache different copies of requested pages for each geolocation that requests them. If WooCommerce sets a cookie for the various locations, then we can use that to create cookie-based varies. The first thing you have to do is find out what the name of that cookie is.

          Then, add a line to your .htaccess like this, where “geo-cookie” is the name of the cookie used by WC:

          RewriteRule .* - [E="cache-vary:geo-cookie"]

          If you’d like more background, we discussed a similar situation in this support thread recently. And this wiki goes into some detail about how it works.

          That’s the extent of my knowledge on the subject 🙂
          If you still need some help after this, please create a ticket through our client area or by sending email to support@litespeedtech.com. The support team can dig a little deeper into your specific setup, if necessary.

          Good luck!

  4. Carly Avatar
    Carly

    Hi,

    We are having an issue with prices displaying minus tax ( woocommerce site ) since installing litespeed cache and its only on mobiles? please assist 🙂

    1. Lisa Clarke Avatar
      Lisa Clarke

      Hi, Carly. Do you have a separate mobile theme? If so, make sure you have LiteSpeed Cache > Settings > Cache > Cache Mobile set to ON. If that doesn’t solve the problem, please join us on Slack or create a ticket through our client area or by sending email to support@litespeedtech.com.

  5. Michael Avatar

    Hello,

    I’m having issue with the woo commerce booking calendar due to this plugin. Once deactivated, works fine. With a previous caching plugin I had the same issue but was able to not cache woo commerce which would prevent the calendar issue. How can I resolve with your caching plugin? Thanks

    -Michael

    1. Lisa Clarke Avatar
      Lisa Clarke

      Please create a ticket through our client area or by sending email to support@litespeedtech.com. It would be helpful if, in that ticket, you provide your Report Number, found in WP Admin > LiteSpeed Cache > Report. Thanks!

  6. Mel Borin Avatar
    Mel Borin

    In your latest version I am not able to find a setting to exclude cookies. You should update this post to reflect this.

    1. Lisa Clarke Avatar
      Lisa Clarke

      Thank you for your feedback. Updating the blog posts is on our list of things to do.

      For now, you can find Do Not Cache Cookies in the LiteSpeed Cache > Cache > Excludes tab.

  7. NIto Frerrer Avatar
    NIto Frerrer

    I’m really troubled your plugin made my site blazing fast but its damaging my other plugin setting Woocommerce One Page Checkout. Please help me!

    1. Lisa Clarke Avatar
      Lisa Clarke

      Hi, Nito. I’m sorry to hear you are having a conflict. Please open a ticket by emailing support@litespeedtech.com and our support team will be happy to help you.

  8. NIto Frerrer Avatar
    NIto Frerrer

    The shortcode for displaying the checkout on any page is not working

Leave a Reply

Your email address will not be published. Required fields are marked *