In a woocommerce store there are multiple product categories, f.x. toys, clothes, shoes, adults
which have a few child categories each. The products from adults
category have to be blurred if it is not the adults
or its child category that is being displayed.
What I do in the loop for now is this:
$for_adults = has_term( 106, 'product_cat' );
if( $for_adults && !is_product_category( 'adults' )){
echo '<img src="'.$image_src.'" alt="'.get_the_title().'" class="product-image blur" title="'.get_the_title().'">';
}else{
echo '<img src="'.$image_src.'" alt="'.get_the_title().'" class="product-image" title="'.get_the_title().'">';
}
The problem is that is_product_category( 'adults' )
, only returns true for when the exact category is being displayed and what needs to be done is that it would return true for when child categories pages are being displayed without hard-coding the category slugs.
Any help or gudance is much appreciated.
Here you go:
@0blongCode the code works fine 🙂 but if the debug mode is on, the following notice appears:
To avoid this we only need to change
to