Limit Search Results to WooCommerce Products

better showcase of your offerings

Limit Search Results to WooCommerce Products

Vanja K.
Vanja K. / December 30, 2020 / 529 Views

Make sure your customers see only WooCommerce products when searching for items on your online store, giving them a better showcase of your offerings

Running a WooCommerce website requires some pretty straightforward tasks at hand each and every day. However, there are also some custom tweaks that some eCommerce admins would like to have for their websites. One of them is displaying just the products on their WooCommerce search page. This is done fairly easily and the code below has been tested with WordPress 5.6 and WooCommerce 4.8.0. However, as always, we advise you to thoroughly test the implementation of these custom code tweaks. In addition, either back up the entire site and database or use a service like Kinsta or WP Engine, which provide daily backups. Here’s the code below:

/** Limit WooCommerce Search Results To Products **/
function search_filter_pproducts($query) {
if ($query->is_search) {
$query->set('post_type', 'product');
$query->set( 'wc_query', 'product_query' );
}
return $query;
}
Copy

If you have any questions or require custom WooCommerce coding, please contact us right away. We’ll be happy to provide you with assistance & services regarding items like these. In the meantime, have a happy holiday!

DISCLAIMER:

Please use the code, advice, and information presented on this website with caution. Nucleus J.D.O.O, or any of its employees, cannot be held responsible for any damages that this code might cause. We always try to update the code shown on our website, but we cannot guarantee its functionality with various themes, templates, or coding. Please ensure that you test each code thoroughly in order to use it safely.

Need some of our services?
Get in
touch and we'll
send you a free cost estimate for your project!

    Contact Form Image
    MORE BLOGS
    We got more related posts, check them out!
    Contact Form 7 Update and Google reCaptcha Issues
    A few weeks ago, Contact Form 7, version  5.8 was released. It brought a lot of bug fixes and it’s one of the most important updates for this highly regarded contact plugin in a while. However, it brought on its own set of problems which we’re dealing with for several of our clients. But, before […]
    Vanja K.
    CEO & CTO
    Read More
    How to remove “Home” from WooCommerce Breadcrumbs
    An easy-to-add snippet of code that will clean up your single product pages and single blog posts This was a simple request, but a rather impactful request by one of our clients. Their eCommerce store, made in WooCommerce by our team displays breadcrumbs on top of their page. It’s a great way of showing the […]
    Vanja K.
    CEO & CTO
    Read More
    How To Add Your Company Logo To The WordPress Login Page
    We get asked this a lot: how to add your company’s logo to the backend login page for WordPress. It makes the whole thing look more prefessional, and in turn, makes the whole thing a lot more appealing to a lot of our clients who have more than one admin or shop manager. The procedure […]
    Vanja K.
    CEO & CTO
    Read More
    Newsletter
    Stay up to date. It's worth it.
    Newsletter Background Image