[Resolved] Page headers – Woocommerce product category image as feature image

Home Forums Support [Resolved] Page headers – Woocommerce product category image as feature image

Home Forums Support Page headers – Woocommerce product category image as feature image

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #647683
    Altti

    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

    GeneratePress 2.1.3
    GP Premium 1.6.2
    #648058
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Currently this isn’t possible unfortunately – but we’re working on a solution 🙂

    #648713
    Altti

    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.

    #648728
    Tom
    Lead Developer
    Lead Developer

    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;
    } );
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.