Back to Community

How to Manage WP Super Cache for WooCommerce Product Pages and Stock Updates

14 threads Sep 16, 2025 PluginWp super cache

Content

If you run a WooCommerce store with WP Super Cache, you might encounter issues where product pages don't refresh automatically after a stock change or a product update. This can lead to customers seeing outdated information, like products that are still listed as out-of-stock after a restock. This guide explains why this happens and provides the most common solutions to ensure your cache is managed effectively for dynamic WooCommerce content.

Why This Happens

By design, WP Super Cache clears the cache for a product page and its related archives (like categories and the homepage) when that product is updated. However, it may not automatically clear cache for custom pages you've created, such as "New Arrivals" or "On Sale" pages built with product blocks. Furthermore, if you use a service like Cloudflare in conjunction with WP Super Cache, it can complicate cache clearing and lead to stale content being served to users.

Common Solutions

1. Exclude Dynamic Pages from Caching

For pages that must always show live data, the simplest solution is to exclude them from being cached. You can do this in the WP Super Cache settings under the Advanced tab. In the Rejected URL Strings box, add parts of the URLs you wish to exclude. For example, if your discount page URL is yoursite.com/discounted-products, you could add /discounted-products to the list.

2. Use the DONOTCACHEPAGE Constant for Specific Conditions

You can use a code snippet in your theme's functions.php file to prevent caching under certain conditions. For instance, to stop out-of-stock product pages from being cached or preloaded, you can use the following code:

if( is_product() && ! defined('DONOTCACHEPAGE') ) {
   global $product;
   if ( ! $product->is_in_stock() ) { 
   define( 'DONOTCACHEPAGE', true ); 
   }
}

This ensures that product pages with no stock are never served from the cache, preventing customers from seeing outdated stock messages.

3. Programmatically Clear Cache for Specific Pages on Product Update

If excluding pages from cache is not desirable for performance reasons, you can write a custom function that hooks into the action triggered when a product is updated. This function can then clear the cache for specific URLs. The following snippet is a starting point; you may need to adjust it for your specific URLs.

function my_custom_cache_clear( $post_id ) {
    // Check if the updated post is a product
    if ( get_post_type( $post_id ) == 'product' ) {
        // Array of custom page URLs to clear
        $urls_to_clear = array(
            home_url( '/new-arrivals/' ),
            home_url( '/discounted-products/' )
        );
        
        global $wp_cache_cleared_posts;
        $wp_cache_cleared_posts = true; // Prevents the default clearing mechanism from running twice
        
        foreach ( $urls_to_clear as $url ) {
            wpsc_delete_url_cache( $url ); // This function deletes the cache for a specific URL
        }
    }
}
add_action( 'save_post', 'my_custom_cache_clear', 10, 1 );

Important Note: The function wpsc_delete_url_cache() is used in this example. Its availability should be verified, as it might be specific to certain WP Super Cache setups. Always test code on a staging site first.

4. Avoid Using Multiple Caching Layers

As mentioned in the sample threads, using WP Super Cache alongside Cloudflare can sometimes cause conflicts where cache is not properly cleared. If you are experiencing persistent issues with stale content, consider disabling either Cloudflare's cache or WP Super Cache to see if the issue resolves. Using multiple caching systems simultaneously often requires very precise configuration to work correctly.

5. Enable Debug Logging to Verify Behavior

If you are unsure whether cache is being cleared correctly, enable the debug logging feature in WP Super Cache. This can be found under the Advanced tab. The debug log will show you exactly which cache files are being deleted when you update a product, helping you verify if your customizations are working or if another plugin (like Elementor) is interfering with the process.

Conclusion

Managing cache for a dynamic WooCommerce store requires a balance between performance and freshness of content. By strategically excluding pages, using conditional code snippets, or programmatically clearing specific cache files, you can ensure your customers always see the most up-to-date information without completely sacrificing site speed. Always remember to test any changes on a development or staging site before applying them to your live store.

Related Support Threads Support