Display WordPress Woocommerce category icon on product page

There is an option in woocommerce-> products -> categories
to assign image for category.

I want to have icons(would be perfect if only from primary category)
to display under price on a single product page.
Can’t find appropriate code to use for that, can you help me with that?

Related posts

Leave a Reply

1 comment

  1. That pretty simple actually, because product categories featured image ( if you have set one ) has been stored as terms meta, which could be retrieved by using

    get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', true );
    

    Here is an idea how you can do it. add the below snippet on your your-theme/woocommerce/single-product/meta.php.

    <?php 
    
            $terms = wc_get_product_terms( $product->id, "product_cat" );
            echo '<ul class="tax_product_cat_list">';
            foreach ( $terms as $term ) {
                $thumbnail_id = get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', true );
                $image = wp_get_attachment_url( $thumbnail_id );            
                if( $image ) {
                    echo '<li><a href="'. get_term_link ( $term ) .'">' . $term->name . ' <img src="' . $image . '" alt="" /></a></li>';
                } else {
                    echo '<li><a href="'. get_term_link ( $term ) .'">' . $term->name . '</a></li>';
                }                                               
            }
            echo '</ul>';
    
    ?>
    

    You might want to update the html structure for your needs.