WooCommerce, How To List Product Categories(With Thumbnails) and Subcategories

IMPORTANT UPDATE! Check out WCCTM PRO, a plugin that provides custom toggle, list and select field menus based on Woocomerce Product Categories.

This code snippet may help you to list product categories and subcategories on your blog or website.

This code snippet may help you to list product categories and subcategories on your blog or website.

Just copy and paste it on a php theme file and make it work!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<div class="menu-categs-box">	
			<?php $wcatTerms = get_terms('product_cat', array('hide_empty' => 0, 'orderby' => 'ASC',  'parent' =>0)); //, 'exclude' => '17,77'
				foreach($wcatTerms as $wcatTerm) : 
					$wthumbnail_id = get_woocommerce_term_meta( $wcatTerm->term_id, 'thumbnail_id', true );
					$wimage = wp_get_attachment_url( $wthumbnail_id );
				?>
				<ul>
					<li class="libreak"><?php if($wimage!=""):?><img src="<?php echo $wimage?>"><?php endif;?></li>
					<li>
						<a href="<?php echo get_term_link( $wcatTerm->slug, $wcatTerm->taxonomy ); ?>"><?php echo $wcatTerm->name; ?></a>
						<ul class="wsubcategs">
						<?php
						$wsubargs = array(
						   'hierarchical' => 1,
						   'show_option_none' => '',
						   'hide_empty' => 0,
						   'parent' => $wcatTerm->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>
					</li>
				</ul>
			<?php 
				endforeach; 
			?>
		</div>

Hope it will be useful for you!

Share on TwitterSave on DeliciousShare via email