Proper hook for W3TC defines, or dynamically disable w3 total cache

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):

Read More
// 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?

Related posts

Leave a Reply

1 comment

  1. 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');