I am trying to show the WooCommerce product child category for the corresponding parent category. I have entered the product as following:
I am using the following code segment that displays the parent category list:
<?php
$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'
);
$categories = get_categories($args);
foreach ($categories as $category) {
echo $category->name;
}
?>
That is working well. Now I want to modify my code segment to display output as below:
Album
English Songs
Modern Songs
Pop
Rock
How can i do it?
I have got the solve of this problem to show the category, Sub-category and product in woocommerce wordpress is as following,
First of all create an array of all the items
Use this function to make recursive n times array from your items
Call function
makeMenu($yourArray,$parentID)