Hi,
You could try something like this:
is_product_category( 'optika-microscopes' ) || cat_is_ancestor_of( 69, get_queried_object()->term_id )
In the snippet 69 is the ID of the optika-microscopes
category, since the cat_is_ancestor_of
function works with IDs and not slugs. So now the menu will be displayed on both parent category archive and its children’s.
-
This reply was modified 8 years ago by
shazdeh.
-
This reply was modified 8 years ago by
shazdeh.
hi,
thanks for your replay.
it’s working in all subcategories, but menu disappears in the single page product.
a little help more?
best regards
hi,
i tryed with is_product_category( 'optika-microscopes' ) || cat_is_ancestor_of( 653, get_queried_object()->term_id ) || (is_product() && cat_is_ancestor_of( 653, get_queried_object()->term_id ))
but it’s not working in product page.
is it the right way?
best regards
hi,
for example using this code is_product_category( 'optika-microscopes' ) || cat_is_ancestor_of( 653, get_queried_object()->term_id ) || (is_product() && has_term( array('brightfield','stereomicroscopes','Inverted Microscopes','camera digital solutions','Refractometers & Polarimeter'), 'product_cat' ) )
i have to add all my subcategories ( i have a lot of subcategories) and it’s working for the 5 subcategories.
i’m looking for a solution for all subcategories of ‘optika-microscopes’
i hope you can help me
best regards
You could try something like this:
has_term( get_terms( array( 'child_of' => 69, 'taxonomy' => 'product_cat', 'fields' => 'names' ) ), 'product_cat' )
get_terms
returns a list of all product_cat
terms that are child of 69, then that is compared against the product_cat terms assigned to the current post with the has_term
function.
thaks a lot for your fantastic support!!!
best regards
@shazdeh
@memwebproject
Hey guys,
has_term( get_terms( array( 'child_of' => 69, 'taxonomy' => 'product_cat', 'fields' => 'names' ) ), 'product_cat' )
when I use this code for each subcategory, they just won’t show up when I click on a parent category. Where am I wrong?
Figured that out myself already.
is_product() && has_term( 'jackets', 'product_cat' ) || is_product_category( '30' ) || cat_is_ancestor_of( 30, get_queried_object()->term_id )
,
where ‘jackets’ has to be replaced with one’s category slug, and ’30’—with a category ID.
my custom code is not working in product page, why? i upgraded woocommerce, in category and subcategories menu appears
my code is:
is_product_category( ‘optika-microscopes’ ) || cat_is_ancestor_of( 653, get_queried_object()->term_id ) || (is_product() && has_term( get_terms( array( ‘child_of’ => 653, ‘taxonomy’ => ‘product_cat’, ‘fields’ => ‘name’ ) ), ‘product_cat’ ))
can you help me?
@memwebproject
Check my reply which is right above yours.
Try to use this code:
is_product() && has_term( 'optika-microscopes', 'product_cat' ) || is_product_category( '653' ) || cat_is_ancestor_of( 653, get_queried_object()->term_id )
hi,
thanks @bzapototskyy but not worked for me.
i have this code : is_product_category( ‘optika-microscopes’ ) || cat_is_ancestor_of( 653, get_queried_object()->term_id ) || (is_product() && has_term( get_terms( array( ‘child_of’ => 653, ‘taxonomy’ => ‘product_cat’, ‘fields’ => ‘names’ ) ), ‘product_cat’ ))
but in product pages stopped to work
@shazdeh can you help me please?