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 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
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.
🌐
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 › 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 › 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 %}
🌐
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…
Find elsewhere
🌐
Shopify Community
community.shopify.com › c › Shopify-Design › if-product-collection-hats-can-this-be-done › td-p › 23008
if product.collection == 'hats' - can this be done? - Shopify Community
May 27, 2013 - {% assign in_hats_collection = false %} {% for collection in product.collections %} {% if in_hats_collection == false and collection.title == 'Hats' %} {% assign in_hats_collection = true %} {% endif %} {% endfor %} {% if in_hats_collection %} One of the collections this product belongs to is the Hats collection. {% endif %} ... Perfect, thanks Caroline. Can you just explain to me why the code below wouldn't work? Just trying to understand liquid better...
🌐
GitHub
gist.github.com › 1002801 › 0c1c54333ce052f4cc202a766a51925acc4c190c
Related Products — to add to product.liquid
Hi, after using this code on top, related products started appearing but images are very large and 4 images apperaing in 4 rows instead of one. I am uhing boundless theme. Please help. Thanks ... Quick question, i have tried implementing the above to the code below but without any luck. How would i go about changing the code below to only display a maximum of 4 random from the collection chosen? {% if settings.display_related_products %} {% capture limit %}{{ settings.products_per_row | plus: 1 }}{% endcapture %}
🌐
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
🌐
GitHub
gist.github.com › jtwray › 9916420a950a0db2b025d8a738763484
Shopify Liquid Cheatsheet · GitHub
Shopify Liquid Cheatsheet. GitHub Gist: instantly share code, notes, and snippets.
🌐
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.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 Community
community.shopify.com › c › Shopify-Design › if-product-in-collection › td-p › 13572
if product in collection - Shopify Community
December 22, 2007 - I got to say, its remarkable how you guys keep pushing liquid into interesting new territories. This goes double for you Christina. Tobias Lütke - Shopify CEO // http://twitter.com/tobi ... Actually, it was Mike who was exactly right. This works: {% capture thisthing %}{{product.handle}}{% endcapture %} {% for product in collections.frontpage.products %} {% if product.handle == thisthing %} <h4>featured product!</h4> {% endif %} {% endfor %}
🌐
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.