WooCommerce – Display nested list of all subcategories on archive-product.php

I solved this by modifying the function linked to in the question to make it recursive. The comments explain my changes:

function woocommerce_subcats_from_parentcat_by_ID( $parent_cat_ID ) {
$args = array(
   'hierarchical' => 1,
   'show_option_none' => '',
   'hide_empty' => 0,
   'parent' => $parent_cat_ID,
   'taxonomy' => 'product_cat'
);
$subcats = get_categories($args);

if ( $subcats ) { // added if statement to check if there are subcategories
  echo '<ul class="product-category-list">';
    foreach ($subcats as $sc) {
      $link = get_term_link( $sc->slug, $sc->taxonomy );
        echo '<li><a href="'. $link .'">'.$sc->name.'</a></li>';
        woocommerce_subcats_from_parentcat_by_ID( $sc->term_id ); // function calls itself
    }
  echo '</ul>';
} else {
  return; //return if no subcategories
    }} // last bracket kept being pushed out of code block if I used a line break

I’m sure there is a more efficient way to do this instead of having the function call itself every time but this works.