
How to hide products without a featured image in WooCommerce
In WooCommerce, having products without a featured image can hurt the visual appeal of your store. It’s best practice to ensure all products have a representative image… but if for some reason some don’t, you can automatically hide them from the catalog.
In this post, I’ll show you how to hide products that don’t have a featured image using a simple PHP snippet. You don’t need to install any additional plugins, and you can implement it easily in your child theme’s functions.php
file or in a custom plugin.
What are we going to do?
We’ll use the woocommerce_product_query
filter to modify the product query and exclude any products that don’t have a featured image (also known as a “thumbnail”).
Add this code to your functions.php file
<?php add_action( 'woocommerce_product_query', 'hideProductsWithoutThumbnail' ); function hideProductsWithoutThumbnail( $query ) { $metaQuery = $query->get( 'meta_query' ); if ( ! is_array( $metaQuery ) ) { $metaQuery = []; } $metaQuery[] = [ 'key' => '_thumbnail_id', 'compare' => 'EXISTS' ]; $query->set( 'meta_query', $metaQuery ); }
How does this code work?
- Hook: We’re using
woocommerce_product_query
, which allows us to modify the product query before displaying the products in the store. - Meta query: We add a condition that requires the product to have a value set for the
_thumbnail_id
field — that’s where WordPress stores the featured image ID. - EXISTS: Only products where the
_thumbnail_id
field exists (i.e., where a featured image is set) will be included in the query.
Where will products without images be hidden?
This code affects the main shop page, product categories, tags, and catalog search results — basically anywhere WooCommerce uses the default product queries. It does not affect the admin panel, so you’ll still see all products there.
What if I want to show a message or default image instead?
Another option is not to hide them but to show a placeholder image or a warning instead. That would involve editing WooCommerce templates, such as content-product.php
, or using a plugin like Code Snippets along with some custom logic.
Keeping your store visually clean and professional is key. With this simple snippet, you can make sure only products with a featured image are displayed — improving the shopping experience for your customers.