I have a site that uses a shopping cart plugin (Shopp), a plugin I wrote, and W3 Total Cache.

In my plugin, I'd like to make sure that W3 Total Cache does not serve any cached pages if the user has any items in their cart, however, I can't seem to find the proper hook to define the constants that will disable W3 Total Cache caching. This is what I have at the very top of my plugin file (the shopp_init function runs during wordpress init):

// do not cache anything if items are in cart
add_action('shopp_init', function(){
    if (shopp_cart_items_count() > 0)
        define('DONOTCACHEDB', true);
        define('DONOTCACHEPAGE', true);
        define('DONOTCACHEOBJECT', true);

It seems like if the DONOTCACHEPAGE constant is detected once for a page, it won't check for it again. So if I have any items in my cart at any point, it'll never cache anything. Likewise, if my cart is empty once, it'll always allow all pages to be cached.

How can I dynamically disable w3 total cache?

  • Interesting question. I would like to know myself. I am working on a shop using Shopp myself these days, and it would be nice to know if it could work with W3 Total Cache. – Lars Koudal Oct 23 '12 at 20:33
  • @LarsKoudal I wasn't able to do what I asked in my original question, but I was able to turn off caching when people have items in their cart using this plugin wordpress.org/extend/plugins/shopp-cache-helper -- the plugin doesn't work directly out of the box though, you need to edit the w3 total cache settings and add the 'shopp_items_in_cart' cookie to the rejected cookies section under each caching type option. – jessica Oct 23 '12 at 21:49
  • Thank you jessica, I will dig into this and make it work. Thanks for pointing me in the right direction :-) – Lars Koudal Nov 6 '12 at 12:42

U could try using this type function:

add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );
    if ( !is_page('Events') ) { 
        wp_deregister_script( 'wpng-calendar' ); 
        wp_deregister_script( 'date-js' ); 
        wp_deregister_script( 'thickbox-js' ); 
        wp_deregister_script( 'jquery-js' ); 
        wp_deregister_script( 'wiky-js' ); 

Found it on this website

U'll have to modify the nandlers to your needs, i found the W3TC handlers to be:

TotalCacheAdmin.php (8 hits)

Line 614:         wp_enqueue_style('w3tc-options');
Line 615:         wp_enqueue_style('w3tc-lightbox');
Line 624:         wp_enqueue_script('w3tc-metadata');
Line 625:         wp_enqueue_script('w3tc-options');
Line 626:         wp_enqueue_script('w3tc-lightbox');
Line 633:         wp_enqueue_script('jquery-ui-sortable');
Line 637:         wp_enqueue_script('jquery-ui-dialog');
Line 642:         wp_enqueue_script('w3tc-options');
  • This answer is not related to my question at all. – jessica Apr 9 '13 at 14:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.