List just subcategory and products of active category page in Woocommerce

The code below works for me in archive-product.php
not sure if it may also work in taxonomy-product_cat.php

EDIT
I’ve added some lines of code to exclude posts previously outputted, since a post can belong to several categories and that’s why you can find always the same posts

    if(is_a(get_queried_object(),'WP_term')){
    $subs=get_terms('product_cat',array('parent'=>get_queried_object()->term_id));
    //var_dump($subs);
    $to_excude=[];
    foreach($subs as $sub){
        $args = array(
            'post_type' => 'product',
            'post_status'=>'publish',
            'post__not_in' =>$to_excude,
            'tax_query' => array(
                    array(
                            'taxonomy' => 'product_cat',
                            'field'    => 'term_id',
                            'terms'    => $sub->slug
                    ),
            ),
    );
    $query = new WP_Query( $args );
    if($query->have_posts()):
        ?>
        <h4><?php echo $sub->name?></h4>
        <?php
        while($query->have_posts()):
            //
            $to_excude[]=get_the_ID();
            $query->the_post();
            the_title();
            // etc
        endwhile;
    endif;
    wp_reset_query();   
    }

}