• Hi,

    Even though it is possible to exclude cart/checkout pages (like for Woocommerce is done by default) through the Exclude URLs field, all other pages are still cached even when someone has added something to his/her cart.

    The result is that sometimes visitors see items in the cart widget (or header cart section, depending on the theme) that do not belong to them. For instance a new visitor might see the cart thingy in the header say “You have 1 item in your cart” (cached page) but when that visitor then reviews his cart, it will be empty (non-cached page).

    To prevent this from happening, Hummingbird should not cache anything when the visitor has (in case of Woocommerce) the “wc_items_in_cart” cookie set. Easy Digital Downloads uses “edd_items_in_cart” and MarketPress would be “mp_items_in_cart”.

    I guess other ecommerce plugins have their own version ending with “_items_in_cart” so that might be something to work with to make it listen to more than just one shopping cart plugin?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Currently using this in wp-config.php for a site with Easy Digital Downloads:

    
    if ( isset($_COOKIE) && ! empty($_COOKIE['edd_items_in_cart']) ) {
      define( 'DONOTCACHEPAGE', true ); // Scare off the Hummingbird
    }
    

    The above works to prevent a visitors cart being cached so that new visitors will not see the previous visitor’s info in the cart widget but it does NOT prevent the user that has added an item to his/her cart to get served cached pages where his/her cart appears empty.

    Is there a similar constant or a hook/filter available to make Hummingbird not serve cached pages to (not logged in) users with items in cart (so a specific cookie set)?

    Hi @ravanh,

    Thank you for reporting this. This will be fixed in one of the upcoming updates.

    Best regards,
    Anton

    Nice πŸ™‚

    Until then: is there a hook or constant I could use to make visitors with a specific cookie receive an non-cached version of each page?

    @ravanh,

    There’s no filter, but I can post what you need to change in the code to make it work, if that works for you.

    Best regards,
    Anton

    Yes please πŸ™‚

    In the plugin directory in file core/modules/class-module-page-cache.php right before

    	/**
    	 * Skip subsite when administrator has turned off page caching.
    	 *

    add

    	/**
    	 * Check if wp_woocommerce_session* is present. It will be present once user adds something to cart.
    	 *
    	 * @since 1.9.3
    	 *
    	 * @see https://docs.woocommerce.com/document/woocommerce-social-login/
    	 *
    	 * @return bool
    	 */
    	private static function has_woo_cookie() {
    		foreach ( (array) $_COOKIE as $key => $value ) { // Input var ok.
    			// Check logged in user.
    			if ( preg_match( '/^wp_woocommerce_session_/', $key ) ) {
    				return true;
    			}
    		}
    
    		return false;
    	}

    In the same file in function should_cache_request replace

    } elseif ( ! isset( $_SERVER['HTTP_HOST'] ) ) { // Input var ok.

    with

    		} elseif ( self::has_woo_cookie() ) {
    			self::log_msg( 'Do not cache page. wp_woocommerce_session* cookie found.' );
    			return false;
    		} elseif ( ! isset( $_SERVER['HTTP_HOST'] ) ) { // Input var ok.

    Best regards,
    Anton

    Ehm… as I read it (correct me if I’m wrong) this does the same as my DONOTCACHEPAGE define in wp-config.php (earlier post) which is prevent a request from being cached.

    What I’m looking for (for complete compatibility) is to prevent a user with a session cookie from being served already cached pages

    This check is used prior to serving a cache file, so users with a session cookie will not be served a cached page.

    Best regards,
    Anton

    OK, thanks, I was just confused by the function name “should_cache_request” then πŸ™‚

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Request: better e-commerce compatibility’ is closed to new replies.