You can do it this way:
1 – get all child terms which belongs the term you want
$args = array(
'taxonomy' => 'product_cat',
'child_of' => 7, put here the id of parent term, which chldren you want to get
'hide_empty' => false,
);
$child_terms = get_terms( $args );
2 – loop through these terms and print there names and posts
if(!empty($child_terms)){
foreach($child_terms as $term){
$args = array(
'posts_per_page' => -1,
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => $term->term_id,
)
),
'post_status' => 'publish',
);
$posts_array = get_posts( $args );
echo $term->name; // subterm name
foreach ($posts_array as $post) {
setup_postdata( $post );
the_title(); //subterm post
}
}
}