This is the code I use to display all product categories with thumbnails:
<?php
$cats = get_terms('product_cat', array(
'hide_empty' => 0,
'orderby' => 'name'
));
?>
<div class="container">
<?php foreach($cats as $cat) : ?>
<?php global $wp_query;
if($cat->category_parent == 0) {
$category_id = $cat->term_id;
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
echo '<li><a href="'. get_term_link($cat->slug, 'product_cat') .'">'. $cat->name .'</a>';
echo '<img src="'.$image.'" width="45px" height="45px" />';
}
?>
<?php endforeach; ?>
</div>
Could anyone help me how to split the categories of subcategories, while having only thumbnails subcategories eg. like this:
category (text)
- subcategory (thumbnails)
- subcategory (thumbnails)
category (text)
- subcategory (thumbnails)
- subcategory (thumbnails)