How to target specific collection instead of default collection ?

How to target specific collection instead of default collection ?

ParthPapat
Tourist
9 0 0

hello Community !

I want to add specific collection name below product name ,but by default random or may be first collection is popping up,is there any way i can target specific collection.

In the screenshot you can see collection name showing as New arrival & Men as these products are added to multiple collection , but i want Oversized collection to appear ,please help me if you are aware about the solutionScreenshot (58).png.

Thank you !

code i used :

{% assign pro_collection = product.collections.first %}
{% if pro_collection %}
This product is part of my {{ pro_collection.title | link_to: pro_collection.url }} Collection
{% endif %}
Reply 1 (1)

ProtoMan44
Shopify Partner
700 57 111

Hey, @ParthPapat  thanks for posting here.
please use this method to show specific collection on product card

{% assign specific_collection = "Oversized" %} 
{% assign matched_collection = null %}

{% for collection in product.collections %}
  {% if collection.title == specific_collection %}
    {% assign matched_collection = collection %}
  {% endif %}
{% endfor %}

{% if matched_collection %}
  This product is part of my 
  <a href="{{ matched_collection.url }}">{{ matched_collection.title }}</a> Collection
{% else %}
  No matching collection found.
{% endif %}
- A thirsty developer passionate about supporting the community. If you'd like to, you can  

Buy me a Coffee.


- Your Shopify Solution Specialist Get a Quote at

ProtoMan44

 - 

Chat On Whatsapp


Crafting exceptional e-commerce experiences to elevate your online presence. Let's build your success story together!