[Plugin: WP Super Cache] Do not cache if cookie present? (3 posts)

  1. bradsucks
    Posted 7 years ago #

    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!

  2. Donncha O Caoimh
    Posted 7 years ago #

    You need to add the "cartItems" cookie name to the .htaccess rules. It should work fine then!

  3. bradsucks
    Posted 7 years ago #

    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...

Topic Closed

This topic has been closed to new replies.

About this Topic