Nicola Mustone

Happiness Lead @ Automattic



Showing Products When No Products Can Be Found

Isn’t the title a bit confusing? I really had no idea about how to explain what this article is about exactly without writing a title that is 20k characters long.

So, let’s try to explain what it is about here.

If a potential customer on your site tries to search for a product it may happen that they won’t find anything. Maybe because the keyword used is too specific, or maybe just because you don’t have what they want. They will land on a page with a message telling them that no products can be found.

How can you try to sell something anyway from that page?

Showing Products When Nothing Else Can Be Found

What we want to do here is to show some products for the customer when no other products can be found.

You may want to show your featured products or just some random products. In this case, we’ll show the 4 most recent products.

So, open the file functions.php in wp-content/themes/your-child-theme-name/ and add this code at the end of the file:

This code is pretty clear. It prints the title You may be interested in… and then a list of four products. You can increase the number of products shown of course, but I’d suggest to not print too many.

Are you wondering how it looks? Here is a screenshot of my local test site with Storefront:

Searching for a keyword does not return any result, but the most four recent products are shown.
Searching for a keyword does not return any result, but the most four recent products are shown.

If you want to show some other kind of products, you can have a look at the shortcodes available in WooCommerce.


Subscribe to This Blog

Receive new articles from this blog directly in your inbox! No spam guaranteed!

Join 670 other subscribers

5 responses to “Showing Products When No Products Can Be Found”

  1. Thank you for another valuable nugget. Would this show up on the 404 Page Not Found template?

    1. Not really Amit, WooCommerce does not have a 404 page. The 404 page is from the theme.

      This shows when you search for a product and there’s none. It’s still kind of a 404 page, but not really.

      1. Any suggestion how to make it show up in 404 since our client’s site is only a shop. No blog.

        1. You can simply use the content of the function from the snippet directly into your 404.php template, where you want the products to appear.

  2. Weekly Roundup: August 4, 2017 – Sell with WP

    […] Ninja Nicola Mustone has a neat tutorial to help you show a few suggested products in WooCommerce when the product search yields no […]

Leave a Reply

You Might Also Like These Articles


Contribute to Improving This Blog

Did you enjoy this article? Was it helpful? Contribute to help me write more articles! The funds collected from this blog are reinvested directly into improving my skills or the blog so that I can provide more and better content!

One-Time
Monthly
Yearly

Make a one-time donation

Make a monthly donation

Make a yearly donation

Choose an amount

€1.00
€5.00
€10.00
€5.00
€15.00
€100.00
€5.00
€15.00
€100.00

Or enter a custom amount


Your contribution is appreciated.

Your contribution is appreciated.

Your contribution is appreciated.

DonateDonate monthlyDonate yearly

Don't Miss a Thing!

Receive new articles from this blog directly in your inbox!

No spam guaranteed!

Join 670 other subscribers

Continue Reading

Discover more from Nicola Mustone

Subscribe now to keep reading and get access to the full archive.

Continue reading