How to display First level child terms of current term’s parent taxonomy?

This code gets all the products parent categories, get_categories its somehow faster than get_terms. if then want the subcategories its just put one more if inside after the echo $cat->name; and so on, before this endif. and its also not showing the empty categories, if it is to show all, just remove the ‘hide_empty’ => true.


$cats = get_categories( array('taxonomy' => 'product_cat', 'hide_empty' => true) );

foreach ($cats as $key => $cat):

    if ($cat->parent == 0):

        echo $cat->name;

    endif;

endforeach;