Excluding Items From Search in Shopify

It’s fairly common to have items for sale in an online store that you don’t necessarily want people to find through the site search. For example, say you want to offer a paid add-on to anyone who buys a certain product. You can send those customers a direct link to the product page or checkout, but you don’t want anyone else to easily find the product on the store. One way to do that is to create the add-on as a regular store product, but then hide it from search. Here’s how to do that.

TL;DR

Tag products you want to hide. Use the tag to hide products in the search results page template and in Ajax results.

Details

Create a tag for excluding products from search. In this case, hide from search.

In search.liquid, add this conditional to the search results loop:

Liquid
{% if item.tags contains 'hide from search' %}{% continue %}{% endif %}

That will make the loop skip over products you want to hide when rendering the search results.

Then in search.json.liquid, add an exclude boolean property to the search result items:

JSON
"exclude"   : {% if product.tags contains 'hide from search' %}true{% else %}false{% endif %}

Finally, in ajax-search-bar.liquid, add a conditional to the loop that adds items to the search results list:

JavaScript
if ( item.exclude ) {
  return;
}

Final note

Your theme may or may not have all of these files, but this covers the two ways search results are delivered (Liquid page template and Ajax). Even if your theme files don’t match this exactly the same principles should apply.