How to Find WooCommerce Product without Featured Images

439 Views Asked by At

I want that the products not showing on the shop frontend who are missing the featured image.

I did not found until now a good solution. I want excluded these products. Looking for a snippet code or an solution i can filter them on the backend, then i can delete.them.

2

There are 2 best solutions below

4
Ashok kumawat On

you can use this query to get products list which does not have featured image

add_shortcode('wp', 'remove_products_without_thumb');
function remove_products_without_thumb(){
if(isset($_REQUEST['delete'] == 'Delete')){
$args = array(
    'post_type' => 'product',
    'posts_per_page' => 10,
    'meta_query' => array(
        array(
            'key' => '_thumbnail_id',
            'compare' => 'NOT EXISTS'
        )
    )
);

$query = new WP_Query( $args );

if ( $query->have_posts() ) {
    while ( $query->have_posts() ) {
        $query->the_post();
        wp_trash_post( get_the_ID() );
        // Display product information here
    }
    wp_reset_postdata();
} else {
    // No products found
}
}
}

Now you can use yourdomain.com?delete=Delete and hit in browser.

1
Vipin Singh On

Yes you can. there is in two way.

  1. Don’t add Thumbnail image when you adding Product item.
  2. Add display none for Product Thumbnail wrapper. ;) Fastest way ;)

Otherwise you can use hooks to remove Remove featured image from showing on product display page 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 '';

}