How to Make WordPress Search Results Page Shows WooCommerce Products Only

If we ask you to mention what is the best e-commerce plugin for WordPress? We are sure that WooCommerce is at the top of your mind. In WordPress communities, WooCommerce is very popular, by far the most popular e-commerce platform, with more than five million active users.

Let’s say you have different types of content on your site. Such as blog posts, pages, and products, and you want to increase your sales. One of the ways we recommend is to make your WordPress search results page only show for your WooCommerce products. This is so that your users will focus on your products—the more people notice them, the more opportunities to sell them.

This article will show you how to make a WordPress search results page show WooCommerce products only, without the help of another WordPress plugin.

Steps to Make WordPress Search Results Page Shows WooCommerce Products Only

Step 1: Prepare your WooCommerce Products

First of all, make sure that you’ve already published some WooCommerce products on your site. If you don’t have any products on your site, you can add them by navigating to Products -> Add New on your WordPress Dashboard.

Step 2: Add the Code Snippet to the functions.php File

By default, WordPress has no options/features to set about what is shown on the search results page; a search results page will show everything related to the specified keyword. This includes pages, posts, products, etc.

As you can see from the GIF above, when we search “chocolate,” the search result page shows any content related to the keyword (chocolate), including our blog posts and products.

Here, we will add the simple code snippet into the functions.php file to make the search results only show for WooCommerce products.

Note: If you are afraid of breaking your site after adding the new function to the functions.php file, you can use the Code Snippets plugin to add a custom function in WordPress. Read here to learn more.

On your WordPress Dashboard, go to Appearance -> Theme File Editor.

Once enter the Theme File editor page, select the functions.php and paste the code snippet below:

Note: Paste the code snippet at the end of the functions file content.

// 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;
}

Once you’ve copied the code snippet, update the theme file by clicking the Update File button.

That’s it. Now your search results page only shows your WooCommerce products. To see how it works, go to your site and test it.

The Bottom Line

This article shows how easily you can make a WordPress results page only shows WooCommerce products without the help of other plugins, just WordPress and WooCommerce. This method is very simple, but this method is not perfect and has weaknesses. When you use the method we explained above; it will impact or implement all your search forms on your site (global search). For example, if you have a search form on your blog post archive, the search results page will show for your WooCommerce products only. It will be a problem. But don’t worry; we have the solution for that issue.

Download and activate JetBlocks. JetBlocks is the best header and footer plugin for Elementor. In this case, the widget that we need is the Search widget.

Note: JetBlocks can work for any Elementor version (free or pro).

By enabling the Is Product Search option on the Search widget settings, you can make your WordPress search results only show your WooCommerce products easily.

You can purchase JetBlocks for a single plugin or buy a bundle of Crocoblock plugins—download JetBlocks on its official website. Please install and activate it once you have downloaded it.

This page may contain affiliate links, which help support our project. Read our affiliate disclosure.
Picture of Akbar Padma

Akbar Padma

Akbar is a WordPress expert and a writer staff at WPPagebuilders. He mainly writes about Gutenberg, Elementor, Divi, and other WordPress page builders.
Want to start a profitable blog with WordPress? OF COURSE!

Leave a Comment

Want to outrank big websites on Google?

Without backlinks, without high DR, without digital PR. Just content optimization.

Click to enlarge.

Hey 👋🏻
Got WordPress knowledge?
Why not turning it into profit? Click the button below to learn how.

Your popup content goes here

50%

Where should we send the template?

After entering your email address, you will be added to our newsletter subscribers. You can unsubscribe anytime.