DevHub Logo
Home/Blog/WooCommerce Cart Not Updating

WooCommerce Cart Shows Wrong Product After Adding to Cart? Fix Session Caching Conflict

Motions Studio Team

July 10, 2026

6 min read
WooCommerce cart issue

The Problem: Cart Page Displays Incorrect Product After Add-to-Cart

Imagine a customer adds a blue t-shirt to their cart, but on the cart page they see a red hat with the wrong price. This strange behavior is a reported bug (WooCommerce GitHub Issue #51944) often caused by object caching plugins like Redis, Memcached, or server-level page caching retaining stale session data. The issue occurs when WooCommerce’s AJAX add-to-cart process updates the cart session, but the cached session or transient still holds the previous product’s data. The result: the cart shows a completely different item. It’s most common on high-traffic stores using persistent object caching or aggressive page caching that caches the mini-cart fragment. The error is intermittent, making it hard to reproduce. Customers get confused, and you risk lost sales and support tickets. The fix involves clearing WooCommerce transients, flushing object cache, and optionally forcing a fresh cart session load.

Step-by-Step Solution

  • 1Reproduce the issue: add a product, then check if cart shows a different product
  • 2Temporarily disable object caching (Redis/Memcached) and see if problem persists
  • 3Flush all WooCommerce transients from WP Admin > WooCommerce > Status > Tools > Clear transients
  • 4Clear your page cache (if using WP Rocket, W3 Total Cache, etc.)
  • 5Switch to a default theme (e.g., Storefront) and deactivate all plugins except WooCommerce to isolate conflict
  • 6Check if the problem occurs only when logged in vs. guest (session handling difference)
  • 7Add the provided code snippet to functions.php to force fresh session loading
  • 8If using a CDN, purge the cache for the cart page
  • 9Update WooCommerce to the latest version (bug may be fixed in newer releases)
  • 10Monitor error logs for any session-related PHP warnings or transients issues
// Add to your theme's functions.php or a custom plugin
// Force WooCommerce to reload the cart session from the database on each page load
add_action( 'wp_loaded', 'wc_force_fresh_cart_session', 1 );
function wc_force_fresh_cart_session() {
    if ( is_admin() || ! function_exists( 'WC' ) ) {
        return;
    }
    // Clear the cached cart to ensure fresh data
    wc_empty_cart_cache();
    
    // If using persistent object cache (Redis/Memcached), flush cart transients
    $transient_key = 'wc_session_' . md5( WC()->session->get_customer_id() );
    delete_transient( $transient_key );
    
    // Re-initialize the session
    WC()->session->init_session_cookie();
}

// Alternative: Clear all WooCommerce transients (run once)
function wc_clear_all_wc_transients() {
    global $wpdb;
    $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_wc_%' OR option_name LIKE '_transient_timeout_wc_%'" );
}
// Uncomment the line below and visit any admin page to run
// add_action( 'admin_init', 'wc_clear_all_wc_transients' );

Final Recommendation

Best Practice

This bug is often a symptom of aggressive caching configurations. For production stores, avoid caching the cart page entirely by excluding it in your caching plugin (e.g., under 'Never cache the following pages'). If you rely on object caching (Redis/Memcached), ensure your session handler is set to database (not object cache) in wp-config.php with `define('WP_SESSION_TYPE', 'database');`. If the issue persists, consider switching to the WooCommerce Cart and Checkout blocks (which use the Store API) instead of the classic shortcodes, as the blocks have better session handling. Always perform a full cache flush after WooCommerce updates and test checkout flow regularly with a guest browser session.

WooCommerce Fixes
Share this guide
M

Motions Studio Team

WordPress developer specializing in debugging, WooCommerce optimization, and PHP compatibility fixes.