I am using wooCommerce and WordPress.
When you set the featured image for a woocommerce product, it shows up as the first/main image in the gallery on the product details page. I don’t want this. I simply want to hide/remove the featured image entirely from the product details page. I want the featured image to only show up in the product category page but not on a single product detail page.
I tried removing the image with the code
remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
in theme functions file.
Still unable to see desired results.
I’m using the theme room09.
I want to hide this vertical image (have set it featured image) from showing on this page only.
<div class="images">
<?php
if ( has_post_thumbnail() ) {
$image = get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ) );
$image_title = esc_attr( get_the_title( get_post_thumbnail_id() ) );
$image_link = wp_get_attachment_url( get_post_thumbnail_id() );
$attachment_count = count( get_children( array( 'post_parent' => $post->ID, 'post_mime_type' => 'image', 'post_type' => 'attachment' ) ) );
if ( $attachment_count != 1 ) {
$gallery = '[product-gallery]';
} else {
$gallery = '';
}
echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<a href="%s" itemprop="image" class="woocommerce-main-image zoom" title="%s" rel="prettyPhoto' . $gallery . '">%s</a>', $image_link, $image_title, $image ), $post->ID );
} else {
echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<img src="%s" alt="Placeholder" />', woocommerce_placeholder_img_src() ), $post->ID );
}
?>
<?php do_action( 'woocommerce_product_thumbnails' ); ?>
</div>
To do this without editing any of the theme files, just add this to a plugin or functions.php in a child theme:
You need to edit the single product image function. I dont know if you have the same plugin as me.
You can block quote the add_action for this on line 93 of woocommerce-hooks.php, it should be in the root directory of plugin folder or in yourtheme/woocommerce/…
It should remove it, if it doesn’t then do this:
Blockquote or remove line 31 in content-single-product.php:
Edit
Rather add a display:none in CSS for the featured image. Go to Appearance – Editor and add this:
CSS:
Finally resolved it. For someone facing similar problem, add this code to the functions file of your theme:
It may depend on the theme you are using. Make necessary changes to the code.
I added both these snippets in my
functions.php
to remove the badge and featured image from the shop page loop.