Limit Search Results to WooCommerce Products

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

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!

Leave a Reply

Your email address will not be published.