如果 Woocommerce 父类别及其子类别的条件

If condition for Woocommerce Parent categories and it's subcategories

我想为我的商店 音乐 类别显示不同的设计模板,与其他类别设计模板相比,它都是子类别。

为此,我添加了以下 if 条件:

if (is_product_category( 'music' ))
{
    wc_get_template( 'archive-product-cubicles.php' );
} else 
{   
    wc_get_template( 'archive-product.php' ); 
}

但上面的代码只显示 Music 父类别的新模板,而不是子类别。

所以如果有人知道解决方案请告诉我。

谢谢, 科坦.

您可以使用以下内容:

if (is_product_category( 'music' ) || cat_is_ancestor_of( MUSIC_ID, get_queried_object()->term_id)
{
  wc_get_template( 'archive-product-cubicles.php' );
} else 
{   
wc_get_template( 'archive-product.php' ); 
}

MUSIC_ID替换为您自己的音乐类别id。