Archived topic
Dynamic image block
1 reply · Started by Søren on December 14, 2022
I'm trying to use the product category thumbnail_id image as META FIELD NAME value when setting type = post meta, but it doesn't output anything.
When setting the type = Featured image it just shows the first product and I would like to use the product category image.
Are there any other way of dynamic outputting a/the category image somehow?
Hi there,
they store it in the term meta, so for now you would need to create a shortcode for that. Try this snippet:
function show_woo_cat_image($html) {
if ( is_product_category() ){
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = get_term_meta( $cat->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
if ( $image ) {
$html = '<img src="' . $image . '" alt="' . $cat->name . '" />';
return $html;
}
}
}
add_shortcode('show_cat_image', 'show_woo_cat_image' );
Then add [show_cat_image] shortcode where you want it displayed.