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
65 2 3

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

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)