On the category page there are different products in the same category which are assigned to a subcategory. Below a single product I want to show the thumbnail of the subcategory which the product is assigned to. I’ve used this code to show the thumbnail:
<?php
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
echo wp_get_attachment_image( $thumbnail_id );
?>
The result is that is shows the thumbnail of the parent category (the category where all these products are in) instead of the subcategory thumbnail.
See here: http://www.solar-discounter.nl/product-categorie/panelen/
I hope someone has the answer for me, thanks in advance.
Solved it!
I replaced the code with the following:
Thanks to Filespit @ StackExchange
(https://wordpress.stackexchange.com/questions/87950/show-category-images-on-single-product-page-and-product-overview-page)
The WooCommerce reference say to do this in themes/yourtheme/functions.php