Skip to content

Instantly share code, notes, and snippets.

@mhmanik
Created July 21, 2016 10:58
Woocommerce display category image
<?php
/**
* http://stackoverflow.com/questions/12717112/how-to-display-woocommerce-category-image
*/
$args = array(
'number' => $number,
'orderby' => $orderby,
'order' => $order,
'hide_empty' => $hide_empty,
'include' => $ids,
'parent' => 0
);
foreach( $product_categories as $cat ) {
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id);
if (!empty($image)) {
echo '<div class="item"><a href="'. get_site_url().'/product-category/'. $cat->slug .'">'.'<img src="'.$image.'" alt="">'. $cat->name . '</a></div>';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment