No results found. Try again with different words?

Search must be at least 3 characters.

Restrict Search Results to WooCommerce Products Only

Sidebar Image

Did not find a solution? We are here to help you succeed.

By default, when visitors use the Search option on your website, the results will show posts, pages, products, etc. that fit the term searched.

If you’re running an online store, you might want to limit the search only to WooCommerce products. This can help users find products faster and increase the conversion rate on your website.

To do this, you would need to add the following filter to the functions.php file of your Child Theme:

add_filter( 'get_search_form', 'astra_get_search_form_callback' );
function astra_get_search_form_callback( $search_form ) {
	$search_form = str_replace( '-1">', '-1"/><input type="hidden" name="post_type" value="product"/>', $search_form ); 
	return $search_form;
}

If you don’t have your Child Theme installed, please check this article on how to do it.

If you are not sure how to add this code, please check this article.

*** Note ***

1. The above-attached filter will not work for the Header Cover Search. Search Box and Full Screen Search.
2. It works with the Slide Search using the header builder search element. Refer to the attached video for a better understanding.

3. It works with the Search Box by replacing the Astra search in the header with the WooCommerce search widget. Refer to the attached video for a better understanding.

Was this article helpful?
Sidebar Image

Did not find a solution? We are here to help you succeed.

Related Docs

Join 1,653,898+ Happy Site Owners Using Astra

Whether you are a beginner, small business owner, or professional web developer, Astra provides all the tools you need to easily build your beautiful WordPress website.

Download is Just A Click Away!

Membership Retention Checklist Download

REWIND

YEAR IN REVIEW

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.

Download Free Astra Theme - Modal Popup Form
Scroll to Top
Now choose your preferred
page builder addon
Choose your preferred page builder addon

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.

Download Free Astra Theme - Modal Popup Form