Woocommerce display sub-categories in parent category page

百般思念 提交于 2019-12-11 08:07:16

问题


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.


回答1:


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

}


来源:https://stackoverflow.com/questions/55968836/woocommerce-display-sub-categories-in-parent-category-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!