Site logo

[Resolved] Remove Featured image in product when a product gallery is present

Home Forums Support [Resolved] Remove Featured image in product when a product gallery is present

Home Forums Support Remove Featured image in product when a product gallery is present

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #1836946
    Design

    Hello!

    I’m trying to remove a featured image on a particular product page. It has a product gallery so we just want to show these once on the page. Is there a simple way to do this with css? Or in the function.php file?

    https://daviddiehmphotography.com.au/product/newcastle-book

    Above is the product I’m referring too.

    Thank you!

    #1836955
    Elvin
    Staff
    Customer Support

    Hi there,

    You can remove it using a PHP snippet.

    Example: Removing the featured product image on product ID 19159.

    function remove_gallery_and_product_images() {
    	$prod_id = get_the_ID();
    	if ( is_product() && $prod_id == 19159 ) {
    	    remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
    	}
    }
    add_action('loop_start', 'remove_gallery_and_product_images');
    #1836957
    Design

    Thanks Elvin,

    We were hoping to keep the images but just show the product gallery images and not the first image (which is the featured image). Does that make sense?

    #1836965
    Elvin
    Staff
    Customer Support

    Try this CSS:

    .woocommerce-product-gallery__image.flex-active-slide {
        display: none !important;
    }

    This removes the huge display but keeps the thumbnail gallery.

    #1836988
    Design

    Sorry – I don’t think I’m explaining it properly! I still want the main image to show, just not the first image in the product gallery – should start on the second image and just have the two images. The first image is the featured image but we don’t want it to show as the first image on the left.

    Does that help? Or still confusing?

    #1837010
    Elvin
    Staff
    Customer Support

    Ah I see what you mean.

    Try this:

    add_filter('woocommerce_single_product_image_thumbnail_html', 'remove_featured_image', 10, 2);
    function remove_featured_image($html, $attachment_id ) {
        global $post, $product;
    
        $featured_image = get_post_thumbnail_id( $post->ID );
    
        if ( $attachment_id == $featured_image )
            $html = '';
    
        return $html;
    }

    This checks the gallery and removes the image if it is the featured image which is usually the first image.

    #1837021
    Design

    Perfection! Thanks so much Elvin 🙂

    Amazing support as always!

    #1837022
    Design

    Sorry – didn’t check all products. Is there a way to only remove it if a product gallery is showing? As there are a lot of products using just one featured image and not the gallery.

    #1837029
    Elvin
    Staff
    Customer Support

    That’s quite tricky.

    A bit of searching lead me to this – https://stackoverflow.com/a/57523746

    Tested and working on my sandbox site.

    #1838019
    Design

    That did it! Thank you so much 🙂

    #1838080
    Elvin
    Staff
    Customer Support

    No problem. Glad to be of any help. 😀

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.