Archived topic
Remove Featured image in product when a product gallery is present
10 replies · Started by Design on June 27, 2021
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!
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');
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?
Try this CSS:
.woocommerce-product-gallery__image.flex-active-slide {
display: none !important;
}
This removes the huge display but keeps the thumbnail gallery.
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?
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.
Perfection! Thanks so much Elvin :)
Amazing support as always!
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.
That's quite tricky.
A bit of searching lead me to this - https://stackoverflow.com/a/57523746
Tested and working on my sandbox site.
That did it! Thank you so much :)
No problem. Glad to be of any help. :D