Woocommerce在父类别页面中显示子类别 [英] Woocommerce display sub-categories in parent category page

查看:162
本文介绍了Woocommerce在父类别页面中显示子类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为子类别创建一个模板,在该模板中我可以显示子类别下的产品,并且在父类别页面中只希望显示父类别的相关子类别.有人可以用代码示例向我推荐吗?如何开始.

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.

推荐答案

尝试以下操作:

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>';
    }

}

这篇关于Woocommerce在父类别页面中显示子类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆