• Resolved janak5

    (@janak5)


    Hi, the Woocommerce products I need to cache are mostly grouped products but there are thousands of products (all in one category) that I don’t need to cache. Is there any way I can exclude all the products for a specific product category?

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi there,

    In order to exclude products from a certain category, or not in a category, you’ll have to use a filter. For example:

    // Do not cache this category
    add_filter( 'wpo_can_cache_page', function( $can_cache_page ) {
    	// If the value is already false, return it.
    	if ( ! $can_cache_page ) return $can_cache_page;
    	if ( in_category( 'no-cache-category' ) ) {
    		return false;
    	}
    	return $can_cache_page;
    } );
    
    // OR Only cache this category
    add_filter( 'wpo_can_cache_page', function( $can_cache_page ) {
    	// If the value is already false, return it.
    	if ( ! $can_cache_page ) return $can_cache_page;
    	if ( in_category( 'only-cache-this-category' ) ) {
    		return true;
    	}
    	return false;
    } );

    Marc.

    Thread Starter janak5

    (@janak5)

    Hi, it didn’t work first time but it worked when I changed:

    if ( in_category( 'no-cache-category' ) ) {

    to

    if ( has_term( 'no-cache-category', 'product_cat' ) ) {

    Thank you very much for your help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Exclude all products from a category’ is closed to new replies.