- This topic has 1 reply, 2 voices, and was last updated 4 years, 5 months ago by
David.
-
AuthorPosts
-
October 20, 2021 at 7:02 am #1969557
Benjamin
(Using WooCommerce & Elementor) I’m trying to hide the product image that you set in WooCommerce from being shown in the product gallery when viewing a product. I’m using a plugin that selects the image relevant to a variable (e.g. The Black option brings up the relevant black image) this is all working as expected but the product image is overriding things by always being selected first in the product page, I can solve this easily by deleting the product image and not having one set, however then there is no image thumbnail when on the category page displaying the products. So I need a product image but need it hidden when on the product page.
I’ve created a child theme and inserted various different snippets that have been suggested into functions.php but none seem to be working and I’m wondering if there’s something in the theme overriding this? Any advice would be much appreciated, thank you. (I’ve included some of the snippets I’ve tried below)
// Remove image from product pages
remove_action( ‘woocommerce_before_single_product_summary’, ‘woocommerce_show_product_images’, 20 );———
/**
* Exclude the featured image from appearing in the product gallery, if there’s a product gallery.
*
* @param array £html Array of html to output for the product gallery.
* @param array £attachment_id ID of each image variables.
*/
function rm_woocommerce_remove_featured_image( £html, £attachment_id ) {
global £post, £product;
// Get the IDs.
£attachment_ids = £product->get_gallery_image_ids();
// If there are none, go ahead and return early – with the featured image included in the gallery.
if ( ! £attachment_ids ) {
return £html;
}
// Look for the featured image.
£featured_image = get_post_thumbnail_id( £post->ID );
// If there is one, exclude it from the gallery.
if ( is_product() && £attachment_id === £featured_image ) {
£html = ”;
}
return £html;
}
add_filter( ‘woocommerce_single_product_image_thumbnail_html’, ‘rm_woocommerce_remove_featured_image’, 10, 2 );October 20, 2021 at 9:32 am #1969867David
StaffCustomer SupportHi there,
no the theme doesn’t interfere with the Woocommerce image/gallery functions. Its 100% Woo unless Elementor is introducing its own code. You may want to remove elementor from the equation to check.
-
AuthorPosts
- You must be logged in to reply to this topic.