Can you please tell me what's wrong with this code ? I can view categories but the subcategories comes as the name of categories .
$orderby = 'name';
$empty = 0;
$args = array(
'orderby' => $orderby,
'show_count' => $show_count,
'hide_empty' => $empty,
);
$all_categories = get_terms( 'product_cat', $args );
$html = '';
if (count($all_categories))
{
$array = $all_categories;
foreach($all_categories as $category)
{
if($category->parent == 0)
{
$html .= '<div class="checkbox"><label><input type="checkbox" class="product-cageories" value="'.$category->term_id.'"> '.$category->name.'</label></div>';
$j = 0;
foreach($array as $index => $child)
{
if($child->parent == $category->term_id)
{
$html .= '<div class="checkbox"><span class="pull-left"> </span><label><input type="checkbox" class="product-cageories" value="'.$category->term_id.'"> '.$category->name.'</label></div>';
unset($array[$index]);
}
if($child->term_id == $category->term_id)
{
unset($array[$index]);
}
}
}
else
{
continue;
}
}
}
echo $html;
wp_die();
I have marketed the problem in the picture . Thank you in advance