If you’ve ever experienced items mysteriously disappearing from the WooCommerce cart or noticed unexpected behavior on your checkout pages, you’re not alone. One common culprit is caching, especially when using plugins like WP Rocket. This guide will walk you through identifying and resolving WooCommerce cart issues step by step, ensuring your eCommerce site functions smoothly.

WooCommerce Cart Items Disappearing when Refreshing

WooCommerce relies heavily on dynamic cart sessions to track products. Improper caching configurations can interfere with this functionality, leading to:

  • Cart items disappearing upon refresh.
  • Errors during checkout.
  • Incorrect cart totals or stale cart data.

Caching tools like WP Rocket speed up your site but need careful configuration to avoid disrupting dynamic WooCommerce features.

Step-by-Step Solution

1. Identify the Problem

Before diving into solutions, determine the source of the issue:

  • Symptoms: Cart items vanish after refresh, dynamic pages don’t update, or customers report cart/checkout failures.
  • Debugging Logs: Enable WooCommerce logs under WooCommerce > Status > Logs and check for errors.

2. Exclude WooCommerce Pages from Caching

WooCommerce pages like /cart, /checkout, and /my-account must never be cached. WP Rocket has built-in support for WooCommerce, but double-check your settings.

  1. Go to WP Rocket Settings:
    • Navigate to Settings > WP Rocket > Advanced Rules.
  2. Exclude WooCommerce Pages: Add the following pages to the “Never Cache URLs” field:
/cart/
/checkout/
/my-account/

    3. Disable Object Caching for WooCommerce

    The following filter in your functions.php can disable object caching in WooCommerce:

    add_filter( 'rocket_cache_reject_wp_super_cache_dynamic', function( $cache ) {
        if ( is_cart() || is_checkout() || is_account_page() ) {
            return true;
        }
        return $cache;
    });

    4.Disable JavaScript Delay for WooCommerce Scripts:

    Go to WP Rocket > File Optimization.Scroll down to “Delay JavaScript Execution” or “Defer JavaScript” and exclude WooCommerce scripts. This prevents WP Rocket from delaying or deferring critical WooCommerce JavaScript.:

    woocommerce
    /wp-content/plugins/woocommerce/

      5. Exclude Cookies Used by WooCommerce:

      WooCommerce uses cookies to manage cart sessions. Add the following to the “Never Cache Cookies” section:

      woocommerce_cart_hash
      woocommerce_items_in_cart
      wp_woocommerce_session_

      6. Disable WP Rocket for Logged-In Users:

      • If you have user-specific data (e.g., saved carts or wishlists), ensure caching is disabled for logged-in users:
        • Go to WP Rocket > Cache.
        • Check the box for “Do not cache pages for logged-in users.”

      Clear WP Rocket Cache:

      • After making the changes, clear WP Rocket’s cache to ensure the new settings take effect.

      Bookmark this guide or share it with your clients to troubleshoot and resolve cart issues effectively. For advanced debugging or development assistance, feel free to reach out!

      Leave a Reply

      Get in Touch

      Please fill out the form below and we will get back to you ASAP

      • This field is for validation purposes and should be left unchanged.