- This topic has 10 replies, 2 voices, and was last updated 4 years, 2 months ago by
Elvin.
-
AuthorPosts
-
June 27, 2021 at 8:39 pm #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!
June 27, 2021 at 9:00 pm #1836955Elvin
StaffCustomer SupportHi 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');
June 27, 2021 at 9:08 pm #1836957Design
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?
June 27, 2021 at 9:24 pm #1836965Elvin
StaffCustomer SupportTry this CSS:
.woocommerce-product-gallery__image.flex-active-slide { display: none !important; }
This removes the huge display but keeps the thumbnail gallery.
June 27, 2021 at 9:51 pm #1836988Design
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?
June 27, 2021 at 10:14 pm #1837010Elvin
StaffCustomer SupportAh 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.
June 27, 2021 at 10:36 pm #1837021Design
Perfection! Thanks so much Elvin 🙂
Amazing support as always!
June 27, 2021 at 10:37 pm #1837022Design
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.
June 27, 2021 at 11:03 pm #1837029Elvin
StaffCustomer SupportThat’s quite tricky.
A bit of searching lead me to this – https://stackoverflow.com/a/57523746
Tested and working on my sandbox site.
June 28, 2021 at 4:25 pm #1838019Design
That did it! Thank you so much 🙂
June 28, 2021 at 7:07 pm #1838080Elvin
StaffCustomer SupportNo problem. Glad to be of any help. 😀
-
AuthorPosts
- You must be logged in to reply to this topic.