Working on a category page - taxonomy-product_cat.php - I want to list all the subcategories of that category page, with all its products. I would think it is simple enough but I cant get it to work.
I can list all categories of the shop with all subcategories and all products - So for example bags would list all products of the whole shop.
Or I can list the subcategories of just the category page - but without the products listed.
How can I list just the subcategories of the category page with their products?
The code I am using that works great, but loops all the categories in the shop, and not just the active category is:
$args = array('taxonomy' => 'product_cat' ); $all_categories = get_categories( $args );
foreach ($all_categories as $cat) {
$category_id = $cat->term_id;
$args2 = array('taxonomy' => $taxonomy,'parent' => $category_id,'hierarchical' => $hierarchical, 'orderby' => $orderby, 'order' => $order,'hide_empty' => $empty); $categories = get_categories( $args2 );
$sub_cats = get_categories( $args2 );
if($sub_cats) {
foreach($sub_cats as $sub_category) {
echo "<h2>".$sub_category->cat_name."</h2>";
$args = array( 'post_type' => 'product','product_cat' => $sub_category->slug, 'orderby' => $orderby, 'order' => $order);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<!--HTML HERE-->
<?php endwhile; wp_reset_query(); }}} ?>