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..
0 Comments