WooCommerce: Sorting categories/subcategories on sub-categories pages too
<p>I have found a WooCommerce code snippet that adds sorting on Category pages, and it works.</p>

<p>But the problem is that the sorting subcategory is only displayed on the Parent category page, but not in the subcategories pages.</p>

<ul>
<li><p>This is the category page:<br><br>
<a href="https://i.stack.imgur.com/582Td.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/582Td.jpg" alt="Categories page"></a></p></li>
<li><p>The problem is that the sorting is not working on subcategory pages:<br><br>
<a href="https://i.stack.imgur.com/fMA0o.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fMA0o.jpg" alt="Sub category page"></a><br><br></p></li>
</ul>

<p>What do I need to change in my code to achieve that?</p>

<p>Here is my code:</p>

<pre><code>function tutsplus_product_subcategories( $args = array()) {
$parentid = get_queried_object_id(); 
$args = array(
    'parent' =&gt; $parentid
);

$terms = get_terms( 'product_cat', $args );

if ( $terms) {

    echo '&lt;ul class="wooc_sclist"&gt;';

        foreach ( $terms as $term ) {

            echo '&lt;li class="category"&gt;';                 


                echo '&lt;h2&gt;';
                    echo '&lt;a href="' .  esc_url( get_term_link( $term ) ) . '" class="' . $term-&gt;slug . '"&gt;';
                        echo $term-&gt;name;
                    echo '&lt;/a&gt;';
                echo '&lt;/h2&gt;';

            echo '&lt;/li&gt;';


        }

        echo '&lt;/ul&gt;';
    }
}
add_action( 'woocommerce_before_shop_loop', 'tutsplus_product_subcategories', 50 );
</code></pre>

<p>Reference: <a href="http://code.tutsplus.com/tutorials/display-woocommerce-categories-subcategories-and-products-in-separate-lists--cms-25479" rel="nofollow noreferrer">Display WooCommerce Categories, Subcategories, and Products in Separate Lists</a> </p>