Archived topic
Page headers – Woocommerce product category image as feature image
3 replies · Started by Altti on August 14, 2018
Hey there,
I'm trying to make a global header for WooCommerce product categories. Is there any way to use the category thumbnail as background image (same way as feature-image)?
Cheers,
Anssi
Hi there,
Currently this isn't possible unfortunately - but we're working on a solution :)
Oh. Too bad. Seems so obvious that it should work like that. I need to think something else then.
Thanks for the quick reply Tom.
If you use the new Page Heros in GPP 1.7, you should be able to use a function like this:
add_filter( 'generate_page_hero_background_image_url', function( $url ) {
if ( function_exists( 'is_product_category' ) && function_exists( 'get_woocommerce_term_meta' ) && is_product_category() ) {
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
if ( $thumbnail_id ) {
$url = wp_get_attachment_url( $thumbnail_id );
}
}
return $url;
} );