How to exclude categories from the search?

The categories terms are displayed in live search when a “Show categories” option is enabled. It’s possible to exclude certain categories from live search.

The solution requires custom PHP snippets. To do it, you have to paste the following code into functions.php in your child theme or use Code Snippets plugin.

To implement the code correctly, you have to know IDs of categories, you want to exclude. You can read category ID from the URL when you are on the category edit page. Take a look at the screen:

Custom code

add_filter('dgwt/wcas/search/product_cat/args', function ($args){

    $args['exclude'] = array(999, 1000, 1001); // The ID of categories to exclude

    return $args;
});

If you use the Pro plugin version, remember to rebuild the search index after implementing the code. To do it got to WooCommerce -> AJAX Search bar -> Indexer (tab) and click “Rebuild index” button.