How to hide sold out products from search results in Shopify

Displaying sold out products on search results could be a source of buyer frustration for clients, since customers could stumble upon products which are not for sale. This is especially relevant if your client is running a flash sale and customers are looking to reach available products quickly.

This is where we will be looking to customize.

  1. From your Shopify admin, go to Online Store > Themes.
  2. Find the theme you want to edit, and then click Actions > Edit code.
  3. In the Templates directory, click search.liquid to open it in the online code editor.
  4. Find to the loop {% for item in search.results %} and {% endfor %}.
  5. Add an IF statement between this FOR loop.
  6. Click Save and you’re done.

Before

After

Note: Since the sold out products are only hidden, this customization could have an affect on pagination. For example, if your search page is set to display 20 products, and five of the loaded products are sold out, you will only see 15 results. If you are seeing extreme cases of blank pages within pagination, you could adjust the pagination towards the max limit of 50 products per page.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *