How to WooCommerce sidebar in display all subcategories to specific category?

The woocommerce products shop page in show/display products all subcategories on category page, if you want to show/display products subcategories in sidebar from a specific category in woocommerce. there children s categories, all under the apparel parent category and specific category id of products to show subcategories in the WooCommerce shop page.

Woocommerce products all subcategories display on sidebar/page

Always use child theme any wordpress website and copy below code and add this code in your function.php for woocommerce all products subcategories shop page. Use this below categories code for display products all subcategories shop page.

function woocommerce_subcats_from_parentcat_by_ID($parent_cat_ID) { $args = array( 'hierarchical' => 1, 'show_option_none' => '', 'hide_empty' => 0, 'parent' => $parent_cat_ID, 'taxonomy' => 'product_cat' ); $subcats = get_categories($args); echo '
    '; foreach ($subcats as $sc) { $link = get_term_link( $sc->slug, $sc->taxonomy ); echo '
  • '.$sc->name.'
  • '; } echo '
'; } function woocommerce_subcats_from_parentcat_by_NAME($parent_cat_NAME) { $IDbyNAME = get_term_by('name', $parent_cat_NAME, 'product_cat'); $product_cat_ID = $IDbyNAME->term_id; $args = array( 'hierarchical' => 1, 'show_option_none' => '', 'hide_empty' => 0, 'parent' => $product_cat_ID, 'taxonomy' => 'product_cat' ); $subcats = get_categories($args); echo '
    '; foreach ($subcats as $sc) { $link = get_term_link( $sc->slug, $sc->taxonomy ); echo '
  • '.$sc->name.'
  • '; } echo '
'; }

afterthen find your product category specific id and get the subcategories under the parent category with the ID example your id this one "15".
and put below code there you want to show/display product subcategories on your page and change your category specific id..

woocommerce_subcats_from_parentcat_by_ID(15);

Post a Comment

0 Comments