Site icon Hip-Hop Website Design and Development

How to exclude woocommerece product category in search results?

I’m looking for a way to exclude a product category from search results with Woocommerce using the pre_get_posts action and $query->set(). I am searching using the WordPress ?s=keyword search. I know that the function will begin like this:

add_action('pre_get_posts', 'exclude_product_category');
function exclude_product_category( $query ) {

    global $wp_the_query;

    if ( ( ! is_admin() ) && ( $query === $wp_the_query ) && ( $query->is_search() ) ) {
       // more code goes here
    }
    return $query;
}

I want to specify something like this:

query_posts( array(
    'post_type' =>'product',
        'tax_query' => array(
           array(
               'taxonomy' => 'product_cat',
               'field' => 'id',
               'terms' => array(18),
               'operator' => 'NOT IN',
               ),
        )
     ));    

How would I accomplish this?