Filtering search results

You may need to include a tax_query for the Woocommerce taxonomy (called ‘product_cat’):

    $tax_query = array(
        array(
            'taxonomy' => 'product_cat'
        ),
    );
    $query->set( 'tax_query', $tax_query );   
}

return $query;
}

However, you’ll have to ensure that you can return posts AND pages AND product categories and also note the search results will be mixed up together.

I would have thought a better solution, rather than filtering at functions.php level, would be to adapt your search.php for the display of the search results. You can then be quite targeted, for instance show:

Posts with this search include:
PostX, PostY, PostZ.

And then another loop with:

Pages with this search include:
PageA, PageB, PageC.

And then another loop with:

Product Categories with this search include:
Product Cat A, Product Cat F, Product Cat Z.

Is that the kind of result you are after, or would you like to filter EVERY search on your site and mix up the results?