WooCommerce subcategories help

    <div class="col-sm-3 col-sm-pull-9 sidebar">
                        <div class="list-group products box">
                            <h4>Product Range</h4>
                            <?php $terms = get_the_terms( $post->ID, 'product_cat' );
                            foreach ( $terms as $term ){
                            $category_name = $term->name;
                            $parent_category_id = $term->term_id;

                            $categories=get_categories(array( 'parent' => $category_id ));
                        $children = get_terms( 'product_cat', array(
                                    'parent'    => $parent_category_id,
                                    'hide_empty' => false
                        ) );
                      foreach( $children as $subcat ){
                            ?>

                            <a href="https://wordpress.stackexchange.com/questions/315072/<?php echo get_category_link($subcat->term_id,"product_cat'); ?>" class="list-group-item"><?php echo $subcat->name; ?></a>
                            <?php } } ?>
                    </div>