Home Forums WoodMart support forum Use last gallery image as product thumbnail in a specific products carrousel

Use last gallery image as product thumbnail in a specific products carrousel

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #655931

    contato-0977
    Participant

    I’m using the “Woodmart Products” carousel widget on my homepage, and I would like to customize it to display the last image from the product gallery as the main thumbnail, instead of the default featured image.

    This change should only apply to a specific carousel where I’ve added a custom el_class — for example: usar-ultima-imagem.

    So far, I’ve tried using the woocommerce_get_product_thumbnail and woodmart_product_image hooks, and also some conditional logic based on $_POST[‘shortcode_atts’][‘el_class’], but none of them seem to affect the product image in the carousel as expected.

    Is there a recommended way (hook, override or filter) within the Woodmart theme to target and change the thumbnail output specifically for one carousel based on its el_class?

    Thank you in advance!

    Best regards

    #656096

    Luke Nielsen
    Keymaster

    Hello,

    Unfortunately, this will not work using a custom class. All we can provide you with is the following custom code, which will change the main product image on all carousels to the last one from the gallery.

    add_action('woodmart_get_product_thumbnail', function ($img, $product, $size, $attach_id) {
    	if ( woodmart_loop_prop( 'is_slider' ) && doing_action('woocommerce_before_shop_loop_item_title') ) {
    		$images = $product->get_gallery_image_ids();
    
    		$image_id = end( $images );
    
    		$custom_size = $size;
    		if ( woodmart_loop_prop( 'img_size' ) ) {
    			$custom_size = woodmart_loop_prop( 'img_size' );
    		}
    
    		$custom_size = apply_filters( 'woodmart_custom_img_size', $custom_size );
    
    		$img = woodmart_otf_get_image_html( $image_id, $custom_size, woodmart_loop_prop( 'img_size_custom' ) );
    	}
    
    	return $img;
    }, 10, 4);

    Kind Regards

    #656175

    contato-0977
    Participant

    Is it possible to change just one carousel, and not all of them?

Viewing 3 posts - 1 through 3 (of 3 total)