WooCommerce: Hide products without featured image

When you’re creating an online store there are many tasks to perform, settings to configure and products to create or import, especially the latter.

Especially when you import products from a catalog of your supplier or your own product sheet from inventory, not all fields are imported, and especially delicate is the image of the product.

We live in a visual world, in which no one NOBODY, will buy a product without an image that shows its appearance and characteristics.

WooCommerce, by default, can put a temporary image, or placeholder as it is usually called, on products without an image, but assume it, you are not going to sell that product, and in the process give a pitiful image of your online store, like an unfinished Ecommerce, poor, sad, something is wrong, unreliable.

This happens when there is no image associated with your product on the product creation screen.

So what I propose is a fairly reasonable solution Ias i see it: Do not show in your online store products that do not yet have product image. Simple don’t you think?

To achieve this you just have to add a little code at the end of the functions.php file of the active theme (child), or if you prefer as a customization plugin, this one:

/* Hide products without featured image */
add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );
function custom_pre_get_posts_query( $query ) {
    $query->set( 'meta_query', array( array(
       'key' => '_thumbnail_id',
       'value' => '0',
       'compare' => '>'
}Code language: PHP (php)

Save the changes and from this moment on any product that does not have an associated image will not be shown in your Ecommerce.

When you add an image it will magically appear, well, thanks to the code above 😉

How useful was this post?

Click on a smiley to rate it!

Average rating 4 / 5. Vote count: 3

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

7 thoughts on “WooCommerce: Hide products without featured image”

  1. Thank you, thank you so much. Spent 5 hours looking for this, analyzing woocommerce files and even starting an advanced tutorial!
    So how do you know what to use in the function? I mean: how did you get to “$query->set”?
    thanks again!

    1. Fernando Tellado

      The key here is the ‘key’ value established with the thumbnail_i = 0, where the code detects if there isn’t a thumbnail image

    1. Dennis,
      I also would like to know this. Have you found out already? Please let me know what the solution is if you have it.
      Thanks in advance!


  2. Hello,

    This solution works fine on the product pages, but when i use shortcode for recent products on my home page, the products without an image also show. Is there a way to fix that also?

    Thanks in advance.

    Nick Vinke

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top