Remove featured image from showing on product display page

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.

Read More

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>

Related posts

Leave a Reply

4 comments

  1. 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. 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;
    }
    
  3. 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.

  4. 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 );