Woocommerce. Check if product belong to specific main category


I wnat to display custom template for produts belongs to specific main category. My category tree is like this:


  • IPA
  • Scout
  • Lager

My code in single-product.php is:

if( has_term( 'beer', 'product_cat' )) {
  wc_get_template_part( 'single-product-beer' ); 
} else {
  wc_get_template_part( 'single-product-default' );

This works fine only if product has "beer" category. But if it is IPA or another child category dont work. How to modify this code to work propertly? (with child categories).

manx 2 months 0 Answers 11 views 0

Leave an answer