WooCommerce: Auto-Hide Products Without a Featured Image

In WooCommerce, having a well-organized product catalog is essential for user experience and conversions. However, some store owners may forget to add featured images to products, leading to empty placeholders that can make the shop look incomplete or unprofessional.

If you want to ensure that only products with a featured image are displayed, you need a way to automatically hide those without one.

Instead of manually checking and updating each product, you can use a simple PHP snippet to exclude products missing a featured image from your shop, category, and search pages. This approach keeps your store looking polished while preventing customers from encountering blank product thumbnails. The best part? It only takes a few lines of code to implement.

Below, I’ll show you how to add this snippet to your themeโ€™s functions.php file or a custom plugin, ensuring that only properly set up products appear in your WooCommerce store.

PHP Snippet: Exclude Products Missing a Featured Image @ WooCommerce Shop Page / Category Page / Search Results / Archives

This PHP code automatically hides WooCommerce products that lack a featured image from standard shop and category pages.

It achieves this by hooking a custom function (bbloomer_hide_products_no_feat_image) into WooCommerce’s main product query process (woocommerce_product_query action).

This function intercepts the query before it runs and modifies its parameters. Specifically, it adds a meta_query condition requiring that the _thumbnail_id meta key (which stores the ID of the featured image) must exist for a product to be included in the results.

This effectively filters out any product without an assigned featured image from the default product listings.

/**
 * @snippet       Hide Products Without Featured Image @ WooCommerce Shop
 * @tutorial      https://businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @compatible    WooCommerce 9
 * @community     https://businessbloomer.com/club/
 */

add_action( 'woocommerce_product_query', 'bbloomer_hide_products_no_feat_image' );

function bbloomer_hide_products_no_feat_image( $query ) {
    $meta_query = $query->get( 'meta_query' );
    $meta_query[] = [
        'key' => '_thumbnail_id',
        'compare' => 'EXISTS',
    ];
    $query->set( 'meta_query', $meta_query );
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

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