Question

I'm really stuck, and wonder if anyone could help. I've tried a few plugins, but none does what I need.

My site needs to have a shop page which shows:

(text only heading) Parent category title  (wine style)

Show :subcategory thumbnails (NOT individual products) (wine range)

(text only heading) Parent category title (wine style)

Show: subcategory thumbnails (NOT individual products) (wine range)

etc.

If I set woo commerce to show subcategories, it will not show nested subcategories in this fashion.

I can't do this via category shortcode, because it will always display the category's individual products, not subcategories.  e.g.

[product_category category="everyday-drinking" per_page="12" columns="4" orderby="date" order="desc"]

I would prefer to be able to do this without nesting categories, but by combining categories and attributes. Ideally under the attribute "EVERYDAY DRINKING", I'd like to display all the wine CATEGORIES which have that attribute - I don't want to display the individual products in each category. i.e.:

(text only heading) ATTRIBUTE=EVERYDAY DRINKING

Show: category thumbnails, (NOT individual products) (wine range)

(text only heading) ATTRIBUTE=FINER DINING

Show: category thumbnails (NOT individual products) (wine range)

etc.

Does anyone have an idea how I could achieve one of these solutions?

Was it helpful?

Solution

OK, this will add just one level of child subcategories underneath each category.

You need to copy the files as described in my previous post and then edit the new file with the following code which should be added after last action hook. Look out for this code <?php do_action( 'woocommerce_after_subcategory', $category ); ?> and the the following before the final </li> tag in the file:

<ul class="wsubcategs">
    <?php
    $wsubargs = array(
    'hierarchical' => 1,
    'show_option_none' => '',
    'hide_empty' => 0,
    'parent' => $category->term_id,
    'taxonomy' => 'product_cat'
    );
    $wsubcats = get_categories($wsubargs);
    foreach ($wsubcats as $wsc):
    ?>
    <li><a href="<?php echo get_term_link( $wsc->slug, $wsc->taxonomy );?>"><?php echo $wsc->name;?></a></li>
    <?php
    endforeach;
    ?>  
    </ul>

Hope that helps.

You can also use the is_shop() to check whether you're on the shop home page (you may only want to show the above under certain circumstances

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top