Show Featured Products for Empty Search Results in WooCommerce
It can happen. And it’s embarrassing. A visitor searches your site for a product and whatever their search terms are, no products are found. Instead of a missed opportunity to convert that visitor into a paying customer, consider showing them some products that might be of interest to them.
If a customer can’t find a product as part of their search, how can I display products the might be interested in?
In this tutorial we’ll show you how to show your featured products as products that might be of interest to your visitors when search fails.
This is a super simple solution that involves just a little bit of code. Open up your theme’s functions.php file and add the following function.
<?php
add_action( 'woocommerce_no_products_found', 'show_featured_products_on_no_products_found', 20 );
function show_featured_products_on_no_products_found() {
echo '<h2>' . __( 'You may be interested in...', 'domain' ) . '</h2>';
echo do_shortcode( '[featured_products per_page="4"]' );
}
You can change the “per_page” number to show more or less products depending on how many features products you have.
Related Articles:

About the Author: Dan Pock
Dan Pock does technical support at Liquid Web with a background in System Administration, Public Relations, and Customer Service. His favorite things include his cats, Oscar Boots, and Dash Nougat; experimenting with PHP; and making up recipes (or at least attempting to). You can find his coding hijinks on GitHub, where he shares most of his projects and open source work.
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.
Latest Articles
2024 cPanel and Plesk pricing breakdown
Read ArticleCentOS Linux 7 EOL — everything you need to know
Read ArticleHow to install Node.js on Linux (AlmaLinux)
Read ArticleUpgrading or installing PHP on Ubuntu — PHP 7.2 and Ubuntu 22.04
Read ArticleWhy is your IP blocked?
Read Article