To exclude products from certain categories from a search,
go to WooCommerce →
choose the “Search config” tab. At the bottom of the config page, you’ll see the following section:
Set the Filtering mode to “Exclude” and then set the Filters to the categories you want to exclude from searches. You can also exclude products with given tags.
Save your changes and rebuild the index. From now on, products from selected categories won’t appear in the search bar.