Do not show the thumbnail row on Woocommerce product page if the product only has 1 image available
In Woocommerce, I have products that contain 1 image (featured image) and other products that have the main featured image as well as additional images added in the gallery.
On the product page, how can I hide the thumbnail row that is display just under the main image but for products that only have 1 image and in the same time keep showing the row in case the product has multiple images.
When viewing a product that has only the main featured image added with no other images in the gallery the product page displays the main image as well as a small thumbnail of it in the thumbnail zone below it. I find this is redundant and the thumb is not needed if it's the only image available. Especially on mobile it looks awkward to display the main image and the same image below it as a thumb
Thank you
Solutions
Try this code.
It will remove
thumbnail image
if it has only one.
function woocommerce_remove_featured_image( $html, $attachment_id ) {
global $post, $product;
$attachment_ids = $product->get_gallery_image_ids();
if ( ! $attachment_ids ) {
return $html;
}
$featured_image = get_post_thumbnail_id( $post->ID );
if ( is_product() && $attachment_id === $featured_image ) {
$html = '';
}
return $html;
}
add_filter( 'woocommerce_single_product_image_thumbnail_html','woocommerce_remove_featured_image', 10, 2 );
Similar questions
Making one row with colspan first row of the Wordpress options page
In my WordPress options page, for creating fields I am using Fluent Framework. It is similar to Meta Box. So both of them use do_settings_fields function and the function generates the code like this: It looks like this: In this table, I want to use firs row as a one row like this: I creted a javascript file to fields/custom_html directory and hide...
How to remove product thumbnail if only one image is added to product WooCommerce
Good I was wondering if i could remove product thumbnail from single product page is product has only one image (i.e the product image only).. So that when user are viewing the product with only one image, they dont need to see the thumbnail but products with product image and Product gallery images, the thumbnail can show up. Is there a way to ach...
Check if any available product has specific attribute
How can you check if there are any products with a specific product attribute in the shop? I could query (eg. with wc_get_products()) all products and check if they (or their variations) are in stock and then collect all the attribute values in an array and test the specific attribute against that array. However, I think that sounds like a huge amo...
Facebook Thumbnail Image Has Correct URL, Old Image
I am having trouble controlling the thumbnail image that appears when I link to my site from Facebook. It is a Wordpress site with a theme, and so I do not feel comfortable trying to edit the header to change the content URL for the og:image. Instead, I deleted the default image that was stored in the location and uploaded my own. When I use the Fa...
Also ask