3rd Mar '26
/
0 comments

How to Redirect WordPress Search to WooCommerce Shop Filter by Product Title or SKU

In the Bricks Facebook group, a user asks:

I'm a bit lost with the product search on my e-commerce site. I have a search bar in my header and I want to display the product archive page with only the results if I type the product name or its SKU. Can anyone help me? I don't quite understand.

One way to do this is by

  1. using a Filter - Search element on the Shop page
  2. configuring it to search for product titles and SKUs
  3. adding a custom search box that sends the search term to the Shop page with the correct URL parameter. Ex.:example.com/shop/?_product=V-Neck+T-Shirtorexample.com/shop/?_product=woo-vneck-tee
  4. adding custom code that redirects WC product title and SKU search terms to the Shop page
  5. additionally, removing products from the default WP search results

This Pro tutorial provides the details of how the above can be done to essentially redirect users to the Shop page with filtered results if the searched term matches a WC product title or SKU. And, if it does n't, to the default WP search results.

Step 1

Set up a Bricks template for Search results.

If you'd like to import it, here's one from our dev site.

Mark the query as the main query. This is needed so we can use pre_get_posts to modify the post types enabled in the search results.

Step 2

Add the following in child theme's functions.php (w/o the opening PHP tag) or a code snippets plugin:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 630 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Related FAQs on Product pages Based on Product Category Taxonomy in Bricks

Related FAQs on Product pages Based on Product Category Taxonomy in Bricks

On product pages, we show all the FAQs associated with the current WooCommerce product's product categories.
Categories:
Pro
Top-Level Product Categories in Bricks

Top-Level Product Categories in Bricks

How to show top-level WooCommerce product categories in Bricks using a query loop.
Categories:
How To Remove the Featured Image from WooCommerce Product Gallery

How To Remove the Featured Image from WooCommerce Product Gallery

Product Gallery on single product pages in WordPress include the product's featured image by default. If you are looking to exclude it so only the…
Categories:
Pro
Stock Quantity Block for WP Grid Builder

Stock Quantity Block for WP Grid Builder

In the unofficial WP Grid Builder Facebook group a user asked: Is it possible to show stock quantity on the card? I can't find it…
Categories:
Pro
On Sale Products Bricks Query Loop

On Sale Products Bricks Query Loop

Looking to show only the WooCommerce products that are on sale in Bricks? Set up a query loop, enable the PHP query editor and paste:
Categories:
[WooCommerce] Product Category Image Background in Bricks

[WooCommerce] Product Category Image Background in Bricks

How to set up the product category thumbnail image as the background of a Section.
Categories: