Woocommerce display sub-categories in parent categ

2019-07-31 11:17发布

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条回答
The star\"
2楼-- · 2019-07-31 11:32

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

}
查看更多
登录 后发表回答