Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: Product showing in collection, but code doesn't say that it belongs to collection

Product showing in collection, but code doesn't say that it belongs to collection

louise100
Shopify Partner
8 0 6

Hi,

 

I'm not sure if this is the correct place to ask this question... but I I am trying to get a badge to show if the product belongs to a certain collection. (Call this Discountcat) This seems to be working for some of the products, but not for all of the products that it should be.

 

I have figured out by adding this code that Shopify doesn't think the product belongs to the Discountcat collection even though it is showing up in the collection and is visible in the admin system

 

 

{% for collection in product.collections %}
{{ collection.title }}
{% endfor %}

 

 

It shows that the product is in a few collections, except for the Discountcat one...even though it shows up?!

 

Has anyone else encountered this?

 

Code for badge

 

{% for collection in product.collections %}
{% if collection.title contains 'Discountcat' %}
<div class="badge">offer</div>
{% endif %}
{% endfor %}

 

 

Thanks in advance

Replies 2 (2)

ShopDoc
Shopify Partner
99 7 9

How is the item being placed in the collection? Manually or auto by tag, category etc?

- Shaun
YouTube
TikTok
louise100
Shopify Partner
8 0 6

Thank you for your reply.

 

The items are being auto added to the collection if they meet 3 criteria (product type equal to ,product tag equal to  and title does not contain x)