Title: Request: better e-commerce compatibility
Last modified: May 23, 2019

---

# Request: better e-commerce compatibility

 *  Resolved [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/request-better-e-commerce-compatibility/)
 * 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)

 *  Thread Starter [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/request-better-e-commerce-compatibility/#post-11565982)
 * 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
       }
       ```
   
 *  Thread Starter [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/request-better-e-commerce-compatibility/#post-11566480)
 * 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)?
 *  [Anton Vanyukov](https://wordpress.org/support/users/vanyukov/)
 * (@vanyukov)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/request-better-e-commerce-compatibility/#post-11567385)
 * Hi [@ravanh](https://wordpress.org/support/users/ravanh/),
 * Thank you for reporting this. This will be fixed in one of the upcoming updates.
 * Best regards,
    Anton
 *  Thread Starter [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/request-better-e-commerce-compatibility/#post-11567681)
 * 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?
 *  [Anton Vanyukov](https://wordpress.org/support/users/vanyukov/)
 * (@vanyukov)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/request-better-e-commerce-compatibility/#post-11567687)
 * [@ravanh](https://wordpress.org/support/users/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
 *  Thread Starter [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/request-better-e-commerce-compatibility/#post-11567740)
 * Yes please 🙂
 *  [Anton Vanyukov](https://wordpress.org/support/users/vanyukov/)
 * (@vanyukov)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/request-better-e-commerce-compatibility/#post-11567861)
 * 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
 *  Thread Starter [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/request-better-e-commerce-compatibility/#post-11568574)
 * 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**…
 *  [Anton Vanyukov](https://wordpress.org/support/users/vanyukov/)
 * (@vanyukov)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/request-better-e-commerce-compatibility/#post-11568784)
 * 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
 *  Thread Starter [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/request-better-e-commerce-compatibility/#post-11571672)
 * 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.

 * ![](https://ps.w.org/hummingbird-performance/assets/icon-256x256.gif?rev=2633221)
 * [Hummingbird Performance - Cache & Page Speed Optimization for Core Web Vitals | Critical CSS | Minify CSS | Defer CSS Javascript | CDN](https://wordpress.org/plugins/hummingbird-performance/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/hummingbird-performance/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/hummingbird-performance/)
 * [Active Topics](https://wordpress.org/support/plugin/hummingbird-performance/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/hummingbird-performance/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/hummingbird-performance/reviews/)

 * 10 replies
 * 2 participants
 * Last reply from: [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * Last activity: [6 years, 11 months ago](https://wordpress.org/support/topic/request-better-e-commerce-compatibility/#post-11571672)
 * Status: resolved