• Resolved sissi

    (@ebiebzh0)


    We are running a WooCommerce shop with different price groups (defined by roles). When a user is logged in the cache is disabled, which is fine, especially for product pages. But we have some (only) content pages which we would like to be served by the cache.
    The question now, should we remove the regex for “disable cache” for logged_in users and then add the shop pages to the cache exclusion list (e.g. overview page, cart, checkout, products, …) or would it be useful to add a specific cache inclusion option for page/post IDs?

    Whats the best practice here?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Anonymous User 16850768

    (@anonymized-16850768)

    By default the cart and checkout pages will not be cached because WooCommerce sets the DONOTCACHEPAGE constant. To confirm, are you wanting the product pages to be cached for logged out users?

    Thread Starter sissi

    (@ebiebzh0)

    Generally I would like all pages to be cached (except, the ones where the donotcachepage is set, which is fine).
    But since we have different prices for different user groups, I need to disable the cache for logged in users, which can be done with the regex for the cookie, that’s fine. Now, I still want to serve some pages cached, regardless if the user is logged in or not (e.g. content pages, that have nothing to do with wooommerce). That’s when I was thinking of an option to “include specific pages to the cache” (like the exclude page id option, but the other way round). Maybe I am thinking too difficult about this and there is an easier way to keep pages cached and others not… I hope this makes it clearer to understand.

    Anonymous User 16850768

    (@anonymized-16850768)

    This would require a custom snippet to handle this, for example:

    if ( is_user_logged_in() && preg_match( '/^\/product\/.+$/', $_SERVER['REQUEST_URI'] ) ) {
        add_filter( 'bypass_cache', '__return_true' );
    }

    The above snippet will bypass the cache if the user is logged in and the page being requested is /product/*. You can customize this regular expression to fit your use case. This would go in your functions.php file.

    (Alternatively, if you load this if statement later, like through a custom plugin, you could use the WooCommerce conditional tags instead of a regular expression.)

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Best practice: WC with different pricing structure and caching?’ is closed to new replies.