1
votes

I'm trying to conditionally remove the product image from both the shop page and the single-product page in WooCommerce. It is removing the image from the single-product but not the product on the /shop page.

//* Conditionally remove the Featured Product Image from the single-product page
function remove_gallery_and_product_images() {
if ( is_product() && is_single(array(1092, 1093, 1094) ) ) {
  remove_action( 'woocommerce_before_single_product_summary', 
'woocommerce_show_product_images', 20 );
  add_filter('body_class', 'no_prod_imgs_class');
  }
}
  add_action('template_redirect', 'remove_gallery_and_product_images');

//* Add CSS for removed featured images from multiple specific product detail 
pages
function no_prod_imgs_class($classes) {
$classes[] = 'no-product-images';
return $classes;
}
5
You're better off removing the image via a hook and not hiding it via CSS. I'll search for the hook for you now :)Andrew Schultz

5 Answers

3
votes

Here's the filter for removing the single product image.

function remove_single_product_image( $html, $thumbnail_id ) {
    return '';
}

add_filter( 'woocommerce_single_product_image_thumbnail_html', 'remove_single_product_image', 10, 2 );

Here is the code for removing the shop page thumbnails.

function remove_woocommerce_actions() {
    remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
}

add_action( 'after_setup_theme', 'remove_woocommerce_actions' );
2
votes

Thank you so much for your answers. I had found those remove actions before and they removed images from the product or /shop page but I wasn't able to target specific product IDs; for whatever reason this remove action doesn't like you targeting specific product IDs! Turns out a working solution was to target a specific page ID instead. So, in other words, in my case, I would have this product on an archive page that will have no product images but another product archive page will include product images.

// Conditionally remove product images from the shop loop
function remove_product_image_conditionally() {
  if ( is_page( 1108 ) ) {
    remove_action( 'woocommerce_before_shop_loop_item_title', 
    'woocommerce_template_loop_product_thumbnail', 10 );
  }
}
  add_action('template_redirect', 'remove_product_image_conditionally');
1
votes

Remove All Thumbnail Images On All Single Product Pages

Add this code to your child themes functions.php file.

remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );

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

You can use these codes to achieve your aim:

// Remove image from product pages
remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );

// Remove sale badge from product page
remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_sale_flash', 10 );

Use the codes above to remove the woocommerce images on single product page. Note the second action removes the sales badge on the single product page, for product on sale.

Then to remove the woocommerce images for the shop page use the action below:

// 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 );

Like before these actions would remove the woocommerce images and the sales badges for the shop page.

0
votes

This removes the product thumbnail in the list

img.scale-with-grid, #Content img {
max-width: 100%;
height: auto;
display: none;

}