Archived topic
Display Product Category image on top of product name on single product page
3 replies · Started by HJ on August 26, 2020
Hi there,
you can use a Hook Element:
https://docs.generatepress.com/article/hooks-element-overview/
Add this code:
<?php
global $wp_query;
$terms_post = get_the_terms( $post->cat_ID , 'product_cat' );
foreach ($terms_post as $term_cat) {
$thumbnail_id = $term_cat->term_id;
$image = wp_get_attachment_image_src( $thumbnail_id, 'thumbnail' );
echo '<img class="woo-single-category-image" src="'.$image[0].'" />';
}
?>
Select the woocommerce_before_single_product_summary hook.
Check execute PHP
And set the Display Rules to Product > All Products
Thanks, updated with code
But im not seeing anything..
I tested that code on a default woo install it works correctly.
On your site i am seeing it has output img tags but with no src which i can only assume is some other code is at play, maybe another plugin or custom template.
Might be worth asking on Woo support to see if they have a solution