简体   繁体   English

Woocommerce在父类别页面中显示子类别

[英]Woocommerce display sub-categories in parent category page

I am trying to create a template for sub-category where I can display products under sub-category and in parent category page want to display only related sub-categories of the parent category. 我正在尝试为子类别创建一个模板,在该模板中我可以显示子类别下的产品,并且在父类别页面中只希望显示父类别的相关子类别。 Can anyone suggest me with the example of code? 有人可以用代码示例向我推荐吗? how to start this. 如何开始。

Try the following: 请尝试以下操作:

if ( is_product_category() ) {

    $terms = get_terms( array('taxonomy' => 'product_cat', 'parent' => get_queried_object_id()  ) );

    foreach ( $terms as $term ){
        $term_link = get_term_link( $term, $taxonomy );

        echo '<a class="ccats" href="'.$term_link.'"><span class="label">'.$term->name.'</span></a>';
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM