WordPress Search result page shows posts, pages, categories, and products. To make the search results page shows woocommerce products only you need to do the following.
- Add the code below to the functions.php file.
// Only show products in the front-end search results
add_filter('pre_get_posts','lw_search_filter_pages');
function lw_search_filter_pages($query) {
// Frontend search only
if ( ! is_admin() && $query->is_search() ) {
$query->set('post_type', 'product');
$query->set( 'wc_query', 'product_query' );
}
return $query;
}
2. The above code can also be added to the code snippet plugin. Download and install the code snippet plugin. Hover on the snippet Menu icon and click on Add New to add a new snippet. Now choose a php snippet and add the above code to it.