Hiding out-of-stock products from your shop catalog is a simple but powerful way to improve the customer experience. By showing only items that are ready to buy, you help customers avoid the frustration of seeing unavailable products and keep their focus on what they can purchase right now. This small tweak can make the shopping journey smoother and even boost your conversion rates.
Solution: How to Hide ‘Out of Stock’ Products in WooCommerce
The code provided below will display only products that are currently in stock on the shop catalog.
add_action('woocommerce_product_query', 'ts_show_only_instock_products'); function ts_show_only_instock_products($query) { $meta_query = $query->get('meta_query'); $meta_query[] = array( 'key' => '_stock_status', 'compare' => '=', 'value' => 'instock' ); $query->set('meta_query', $meta_query); }
Output
When a customer visits your shop, all out-of-stock products in your store will now be hidden on the shop catalog and archive pages.
If you’re exploring more ways to improve your shop, don’t miss our earlier post! We’ve covered how to gray out ‘Out of Stock’ variations in WooCommerce, making it easier for your customers to see what’s available.