We’ve already seen how to only display products from a single category on the Shop page. Today, we’ll do something similar, but we’ll target the search result.
Code is somewhat similar to the example I linked to above, so it will use once again the “pre_get_posts” filter in order to modify the query before products are returned on the screen. Enjoy!
I’ve searched for “courses” here, and because the snippet below is active, no search result (WooCommerce product) will show from the “Courses” category.
PHP Snippet: Exclude Products From a Given Category @ WooCommerce Search Result Page