2

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>
2
  • Did you buy the theme with the woocommerce installed already? Or add it as a plugin after installing the theme? Jun 24, 2013 at 15:14
  • i added theme after installing woocommerce .........
    – dhruv
    Jun 24, 2013 at 15:20

4 Answers 4

4

To do this without editing any of the theme files, just add this to a plugin or functions.php in a child theme:

add_filter('woocommerce_single_product_image_thumbnail_html', 'remove_featured_image', 10, 3);

function remove_featured_image($html, $attachment_id, $post_id) {
    $featured_image = get_post_thumbnail_id($post_id);
    if ($attachment_id != $featured_image) {
        return $html;
    }
    return '';
}
2
  • Can you please explain the code? What does 10 and 3 refer to here? Aug 12, 2014 at 13:09
  • @SamarthAgarwal the 10 and 3 are used by the add_filter function. 10 being what order in which this is called, since you can have multiple functions via the same filter and 3 is the number of variables passed since the default is one.
    – sirmdawg
    Mar 24, 2015 at 18:56
0

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/...

//add_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
//add_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );

It should remove it, if it doesn't then do this:

Blockquote or remove line 31 in content-single-product.php:

//do_action( 'woocommerce_before_single_product_summary' );

Edit

Rather add a display:none in CSS for the featured image. Go to Appearance - Editor and add this:

CSS:

.yith_magnifier_zoom_wrap{
    display: none !important;
}
13
  • hey i commented line in content-single-product.php . but that removed all of my images. i merely need to remove featured image. kindly check the page.
    – dhruv
    Jun 24, 2013 at 15:59
  • So you want to do what exactly.. Remove just the big image and keep the other images for the product? Jun 24, 2013 at 16:11
  • i want it to show on all other pages (widgets and category page etc) but not on the product display page.
    – dhruv
    Jun 24, 2013 at 16:14
  • Please put that in your question in future.Add back the do_action but in the hooks file, swap 'woocommerce_show_product_images' with the 'woocommerce_show_product_thumbnails'. Jun 24, 2013 at 16:16
  • Try the above, so we can see what you get Jun 24, 2013 at 16:17
0

Finally resolved it. For someone facing similar problem, add this code to the functions file of your theme:

if ( ! empty( $attachment_ids ) ) array_unshift( $attachment_ids, get_post_thumbnail_id() );

if ( empty( $attachment_ids ) ) return;

It may depend on the theme you are using. Make necessary changes to the code.

1
  • Does this still work with the current version of WooCommerce? Any words of advice for someone currently struggling with this problem? Thanks.
    – SAHM
    Sep 21, 2015 at 0:17
0

I added both these snippets in my functions.php to remove the badge and featured image from the shop page loop.

// Remove product images from the shop loop
remove_action( 'woocommerce_before_shop_loop_item_title','woocommerce_template_loop_product_thumbnail', 10 );

// Remove sale badges from the shop loop
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10 );

Not the answer you're looking for? Browse other questions tagged or ask your own question.