This is what ended up working:

{% for c in product.collections %}
{% if c.handle == "discontinued" %}
This product is Discontinued 
{% endif %}
{% endfor %}
Answer from Crystal Groves on Stack Overflow
🌐
Shopify
shopify.dev › docs › api › liquid › objects › collection
Liquid objects: collection
If the first product in the collection doesn't have a featured image, then nil is returned.
🌐
Myshopify
liquid-sandbox-2.myshopify.com › pages › check-if-a-collection-has-products
Check if a collection exists and has products - Liquid sandbox
<h4>Good way, using == blank check</h4> {% for i in (1..5) %} {% capture key %}collection_{{ i }}{% endcapture %} {% unless settings[key] == blank or collections[settings[key]] == blank or collections[settings[key]].products_count == 0 %} {{ collections[settings[key]].title }} has {{ collections[settings[key]].products_count }} {{ collections[settings[key]].products_count | pluralize: 'product', 'products' }}<br> {% endunless %} {% endfor %} <h4>Good way, using != blank check</h4> {% for i in (1..5) %} {% capture key %}collection_{{ i }}{% endcapture %} {% if settings[key] != blank and collect
🌐
Shopify
shopify.dev › docs › api › liquid › objects › product
Liquid objects: product
A product in the store. ... Returns true if at least one of the variants of the product is available. Returns false if not. For a variant to be available, it needs to meet one of the following criteria: ... The variant has an associated delivery profile with a valid shipping rate. ... The collections that the product belongs to.
🌐
Shopify Community
community.shopify.com › technical q&a
Conditional snippet if product is contained in a Collection?
August 14, 2020 - Need help on how to code conditional snippets so that the snippet is only displayed if the product is contained in a certain Collection. What I want to accomplish is to have a snippet included on specific Products if th…
🌐
Shopify Community
community.shopify.com › c › Shopify-Design › If-product-in-specific-collection › td-p › 41092
If product in specific collection - Shopify Community
June 20, 2013 - Hey Elliott! This is on the product.liquid template, correct? You can do this: {% if product.collections contains 'set-one' %} Lorizzle i'm in the shizzle doggy sizzle amizzle, pizzle adipiscing elit. Sure my shizz velizzle, rizzle volutpizzle, gangster quis, gravida vel, daahng dawg.
🌐
Shopify Community
community.shopify.com › technical q&a
If product is in a specific collection, show specific code on page
April 14, 2022 - So I am working on a product specifications table for our website and I would like for the code to show certain aspects of that table based off an if else or case statement. For example, we have various appliances and i…
🌐
Shopify
shopify.github.io › liquid-code-examples › example › collection-page
Collection page | Shopify Liquid code examples
<style> .product-card { box-sizing: border-box; float: left; min-height: 1em; padding-left: 2em; vertical-align: top; width: 25%; } .visuallyhidden { border: 0; clip: rect(0 0 0 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px; white-space: nowrap; } </style> <h1>{{ collection.title }}</h1> {%- if collection.description != blank -%} <p>{{ collection.description }}</p> {%- endif -%} <ul> {%- for product in collection.products -%} <li> <a class="product-card" href="{{ product.url | within: collection }}"> <img src="{{ product.featured_image.src | img_ur
🌐
Shopify Community
community.shopify.com › c › shopify-design › check-if-a-collection-has-products-or-not › td-p › 1927963
Solved: Check if a collection has products or not? - Shopify Community
October 3, 2023 - This is an accepted solution. ... {% if collection.products.size > 0 %} {% for product in collection.products %} {{ product.title }} {% endfor %} {% else %} <p>This collection has no active products.</p> <a href="/" class="btn">Return to Homepage</a> {% endif %}
Find elsewhere
🌐
Markdunkley
cheat.markdunkley.com
Shopify Cheat Sheet - Liquid variables
Returns a collection of all of this product's variants. ... Returns false if all variants' quantities are zero and their policies are set to "stop selling when sold out". ... If using a custom product template (like product.bike-landing.liquid) then it will return the name of the template ...
🌐
Shopify Community
community.shopify.com › c › Shopify-Design › If-product-in-collection-show-this › td-p › 26206
If product in collection, show this - Shopify Community
July 20, 2021 - What is the full script for this? Looking for similar answer. ... {% assign found = false %} {% for c in product.collections %} {% if c.handle=='merchandise' %} {% assign found = true %} {% endif %} {% endfor %} {% if found %} // do whatever you want {% endif %}
🌐
Shopify
shopify.github.io › liquid-code-examples › example › collection-list
Collection list | Shopify Liquid code examples
--> {%- if collection.image -%} {%- assign collection_image = collection.image -%} {%- elsif collection.products.first and collection.products.first.images != empty -%} {%- assign collection_image = collection.products.first.featured_image -%} {%- else -%} {%- assign collection_image = blank -%} {%- endif -%} <a href="{{ collection.url }}"> <img src="{{ collection_image | img_url: '480x' }}" alt=""> {{ collection.title }} </a> </li> {%- endfor -%} </ul>
🌐
GitHub
gist.github.com › jtwray › 9916420a950a0db2b025d8a738763484
Shopify Liquid Cheatsheet · GitHub
Shopify Liquid Cheatsheet. GitHub Gist: instantly share code, notes, and snippets.
🌐
Shopify
shopify.dev › docs › api › liquid › objects › collections
Liquid objects: collections
<a href="/collections/empty" title="">Empty</a> <a href="/collections/featured-potions" title="">Featured potions</a> <a href="/collections/freebies" title="">Freebies</a> <a href="/collections/frontpage" title="">Home page</a> <a href="/collections/ingredients" title="">Ingredients</a> <a href="/collections/potions" title="">Potions</a> <a href="/collections/sale-potions" title="">Sale potions</a> ... You can use collections to access a collection by its handle. ... {% for product in collections['sale-potions'].products %} {{- product.title | link_to: product.url }} {% endfor %}
🌐
Shopify
shopify.dev › docs › api › liquid › objects › all_products
Liquid objects: all_products
If you want more than 20 products, then consider using a collection instead. ... _products to access a product by its handle. This returns the product object for the specified product.
🌐
Reddit
reddit.com › r/shopify › how to get only available product count of a collection?
r/shopify on Reddit: How to get only available product count of a collection?
December 30, 2023 -

I am using BeYours Theme from Shopify Theme Store.

I was able to edit the theme code to only count available products when showing the count

Screenshot

Used the following code for the count:

{% for product in collection.products %}
  {% if product.available %}
    {% assign available_products = available_products | plus: 1 %}
  {% endif %}

{% endfor %}

This works fine on the collection page but on the Search Results page, it shows the correct count if the result count is less than 10. If the results are more than 10, it will show "10".

I am not able to fix this count. Here's the code for search template:

{% for product in search.results %}
    {% if product.available %}
      {% assign available_products = available_products | plus: 1 %}
    {% endif %}

{% endfor %}

How can I get the correct Search results count?

🌐
Shopify
shopify.com › partners › shopify-cheat-sheet
Shopify Cheat Sheet — A resource for building Shopify Themes with Liquid
Returns the URL of the next product in the collection. Returns nil if there is no next product. This output can be used on the product page to output ‘next’ and ‘previous’ links on the product.liquid template.