WordPress.org

Support

Support » Plugins and Hacks » [Plugin: WP Super Cache] Do not cache if cookie present?

[Plugin: WP Super Cache] Do not cache if cookie present?

  • I’m trying to make WP Super Cache work with a shopping cart (so that if the $_COOKIE[‘cartItems’] variable is greater than zero the visitor is served dynamic pages).

    I’ve tried making my own plugin as I’ve read here and here, but I’m not having much luck. Here’s my plugin code:

    function wp_supercache_dontcachecart( $string ) {
    
    	if( $_COOKIE[ 'cartItems' ] > 0 ) {
    		$string = 'cartItems';
    	}
    
    	return $string;
    }
    add_cacheaction( 'wp_cache_get_cookies_values', 'wp_supercache_dontcachecart' );

    Any idea what I’m doing wrong? Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You need to add the “cartItems” cookie name to the .htaccess rules. It should work fine then!

    Thanks donncha! I modified both lines in the htaccess to be:

    RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_|cartItems).*$

    It works a bit better (I think) but it still seems to be a random toss-up whether I get a cached page or a dynamic page when I’m logged out and using the shopping cart. Not sure why that is…

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: WP Super Cache] Do not cache if cookie present?’ is closed to new replies.
Skip to toolbar