Exclude Out of Stock products from search
Hi there,
We've used Brizy template to build a search results page. This works fine but we want to exclude products that are out of stock from the search - we've ticked Catalog visibility: Shop Only under Catalogue Visibility on an individual product.
Now, is this down to the Brizy search template or part of WooCommerce and / or the theme (OceanWP)?
Thanks,
Darren
-
Hi,
Unfortunately, at the moment it isn't possible to add a condition to the Archive or Products element to exclude the "Out of stock" products but I will inform our team about this suggestion and they will investigate it deeply.
Thank you!
Best regards,
Sandra0 -
That's great thanks.
We found a solution with some php that hides all products out of stock from search.
As follows:
/*Hide Out of Stock from search*/
add_action( 'pre_get_posts', 'hide_out_of_stock_in_search' );
function hide_out_of_stock_in_search( $query ){
if( $query->is_search() && $query->is_main_query() ) {
$query->set( 'meta_key', '_stock_status' );
$query->set( 'meta_value', 'instock' );
}
}0 -
Ohh, great! Thank you very much for sharing with us the workaround and solution you found! Hope it will be useful for other users too!
Best regards,
Sandra0
Please sign in to leave a comment.
Comments
3 comments