简体   繁体   中英

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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