Show Product Category Image on Product Page in Woo Commerce


1. Go to the:-  /wp-content/plugins/woocommerce/templates/single-product

2. Find and Edit meta.php

3. Find this Code:-

<?php
$size = sizeof( get_the_terms( $post->ID, ‘product_cat’ ) );
echo $product->get_categories( ‘, ‘, ‘<span class=”posted_in”>’ . _n( ‘Artist:’, ‘Artist:’, $size, ‘woocommerce’ ) . ‘ ‘, ‘.</span>’ );
?>

4. Replace With :-

<span class=”posted_in”>
<?php
$prod_categories = get_the_terms($post->ID, ‘product_cat’ );
foreach( $prod_categories as $prod_cat ) :
$cat_thumb_id = get_woocommerce_term_meta( $prod_cat->term_id, ‘thumbnail_id’, true );
$cat_thumb_url = wp_get_attachment_thumb_url( $cat_thumb_id );
$term_link = get_term_link( $prod_cat, ‘product_cat’ );
?>

<a href=”<?php echo $term_link; ?>”>
<?php if($cat_thumb_url){ ?>
<span class=”artist-name”><img src=”<?php echo $cat_thumb_url; ?>” alt=”<?php echo $prod_cat->name; ?>” /></span>
<?php } ?>
<span class=”artist-image”><?php echo $prod_cat->name; ?></span>
</a>

<?php endforeach; wp_reset_query(); ?>
</span>

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s