MBrown
MBrown

Reputation: 31

How to display a custom text only for a specific product category AND his child category in Woocommerce archive page

I want to display a custom text in woocommerce archive page, for a specific product category and all his child categories.

I used that code in woocommerce >> archive-product.php

if (is_product_category( 'world-fashion' ) || cat_is_ancestor_of(247, 
get_queried_object()->term_id)){ echo "my custom text";}
else { echo "another text"; }

my custom text is ONLY displayed when the parent category (world fashion ) is selected. How to show it for all his child categories ?

Upvotes: 0

Views: 1705

Answers (1)

raju_odi
raju_odi

Reputation: 1475

use below code to check children categories and make sure world-fashion category id must be 247

if (is_product_category( 'world-fashion' ) || term_is_ancestor_of(247, 
get_queried_object()->term_id,'product_cat'))
{ 
   echo "my custom text";
}
else 
{ 
  echo "another text"; 
}

Upvotes: 1

Related Questions