Coding for displaying available sizes under the product cards

Coding for displaying available sizes under the product cards

jbags
Shopify Partner
12 0 3

Hi there!

I would like to show the size variants below the product card when I'm in "collection view".  I've included a screenshot below of what I am looking for.  

 

I'm on the free Dawn theme.

If someone has the right coding, and wouldn't mind telling me exactly where to go to plug it in, I would be forever grateful!
Screen Shot 2025-01-29 at 2.21.16 PM.png

Replies 18 (18)

KoryP
Shopify Partner
5 0 0

That's a little bit involved, but you can add the variants to card-product.liquid after line 207 ... you can see how variant options are handled on product pages (main-product.liquid) in product-variant-picker.liquid, which loops through product.options_with_values and renders product-variant-options.liquid.  The specifics depend on how you implemented sizes for your variants, but that should get you in the right area.  And, of course, there'd be some css work to match your design.

I would be happy to be your Shopify Solutions Specialist if you need further assistance. Please "send a message" via my profile page.

Shadab_dev
Shopify Partner
1542 81 170

Okay so open your card-product.liquid file and add all this code

//////////// Code ////////////
{% if card_product.available %}
<div style="text-align:center; position: relative; z-index:10; " class="product-sizes">
<!-- Loop through all product options -->
{% for option in card_product.options_with_values %}
<!-- Check if the option name is 'Size' -->
{% if option.name == 'Size' %}
<!-- Loop through all values of the 'Size' option -->
{% for value in option.values %}
<!-- Find the matching variant for the current option value -->
{% assign variant_id = '' %}
{% for variant in card_product.variants %}
{% if variant.option1 == value or variant.option2 == value or variant.option3 == value %}
{% assign variant_id = variant.id %}
{% endif %}
{% endfor %}

<!-- Display the size option with a data-variant attribute -->
<a
data-variant="{{ variant_id }}"
style="margin:0 20px; cursor:pointer; text-decoration: none !important; color: #000000; border: 2px solid black; padding: 5px 10px; background: whitesmoke;"
href="{{ card_product.url }}?variant={{ variant_id }}"
>
{{ value }}
</a>
{% endfor %}
{% endif %}
{% endfor %}
</div>
{% endif %}
///////// Code End ////////

Place this code here

Shadab_dev_0-1738228804014.png

 


Just between the two closing div's. You can style it as per your need. Hope this helps.

Buy me Coffee, if you feel i was helpful. Email Me here or WhatsApp me with this link for any help with shopify theme customizations or any project in web dev. If this is helpful, please Like and Accept the solution.
jbags
Shopify Partner
12 0 3

Thank you SO much!! Ok, so I put it in there, and it added the sizing boxes correctly, but the boxes are super low and laying on top of the product card below them.  Do you know what I would do to move them up right below the product cards? I've included a screenshot of where they are sitting. Other than that, it appears to work GREAT!  I appreciate you SO much! Truly!
Screen Shot 2025-01-30 at 1.56.52 PM.png

Shadab_dev
Shopify Partner
1542 81 170

Send me the store link

Buy me Coffee, if you feel i was helpful. Email Me here or WhatsApp me with this link for any help with shopify theme customizations or any project in web dev. If this is helpful, please Like and Accept the solution.
jbags
Shopify Partner
12 0 3

I took the code off since it wasn't displaying quite right, but this is the link.  I can't add you as a collaborator though, this is my clients site, I'm trying to fix this for her. Thank you so much!!!

Shadab_dev
Shopify Partner
1542 81 170

Please duplicate the theme and add the code to it and send me the link for the duplicate theme preview. I will need to see the changes I am making to put in the right place. 

Buy me Coffee, if you feel i was helpful. Email Me here or WhatsApp me with this link for any help with shopify theme customizations or any project in web dev. If this is helpful, please Like and Accept the solution.
jbags
Shopify Partner
12 0 3

Ok, so I duplicated it and then clicked this preview button, and this is the link!  I hope I did that correctly!  I REALLY appreciate your help!

 

Screen Shot 2025-02-01 at 5.21.56 PM.png

Shadab_dev
Shopify Partner
1542 81 170

You will need to add my code as well in this duplicate theme from the code editor like you did for the live one 

Buy me Coffee, if you feel i was helpful. Email Me here or WhatsApp me with this link for any help with shopify theme customizations or any project in web dev. If this is helpful, please Like and Accept the solution.
jbags
Shopify Partner
12 0 3

Ah thank you! I got that code added in, and here is the link for the preview with that code added.  Thank you so much!!!

Shadab_dev
Shopify Partner
1542 81 170

I dont think you have added the code correctly, i dont see the size boxes i coded. Add the code as mentioned before  in the  duplicate theme as well

 

Buy me Coffee, if you feel i was helpful. Email Me here or WhatsApp me with this link for any help with shopify theme customizations or any project in web dev. If this is helpful, please Like and Accept the solution.
jbags
Shopify Partner
12 0 3

Hi there! I'm seeing them on there! Here's a few links to some of the collections where I'm seeing the boxes in there! They're just super low and almost on top of the product card below them!  I can also send you a file of the downloaded code if you'd like. Thank you so much!  Here's the preview link again: here.  
Denim
Dresses
Tops
Bottoms

Screen Shot 2025-02-05 at 12.11.21 PM.png

Screen Shot 2025-02-05 at 12.09.10 PM.png

Shadab_dev
Shopify Partner
1542 81 170

Man i am sorry but i don't see the list. I need you to duplicate the theme, edit code on that duplicate one like explained above and share me the preview link for the duplicate one and not the live one.. The link you have inserted, i dont see the sizes on that.

Buy me Coffee, if you feel i was helpful. Email Me here or WhatsApp me with this link for any help with shopify theme customizations or any project in web dev. If this is helpful, please Like and Accept the solution.
jbags
Shopify Partner
12 0 3

Ok I think I figured out where I went wrong with the link.  Try this one: here.  I also filmed a video showing you where I got the link here, so if it's wrong, just let me know where to find the correct one! Hopefully I got it right this time. Thank you so much!

Shadab_dev
Shopify Partner
1542 81 170

Yes you got it right this time, but it will be difficult to share the code cause it will be a lot of adjustments due to screen size differences.

If its okay with you let me know i can help you out over a call.

Buy me Coffee, if you feel i was helpful. Email Me here or WhatsApp me with this link for any help with shopify theme customizations or any project in web dev. If this is helpful, please Like and Accept the solution.
jbags
Shopify Partner
12 0 3

Ah ok, I can do next week, what are some times that work for you?

Shadab_dev
Shopify Partner
1542 81 170

Yeah, let's do mon around 3 to 3:30 pm IST.

Buy me Coffee, if you feel i was helpful. Email Me here or WhatsApp me with this link for any help with shopify theme customizations or any project in web dev. If this is helpful, please Like and Accept the solution.
jbags
Shopify Partner
12 0 3

Hi there! I'm on EST, would there be any way that you could talk around 9:30 or 10 am IST?  That's 10:30 or 11 pm for me. If so, let me know what day. And also how we would talk. Zoom? 

Shadab_dev
Shopify Partner
1542 81 170

9:30 or 10 am IST I can do this time but on weekends. So lets do it this saturday. And Yes we can join on zoom or gmeet. Also try get in touch with whatsapp may be, the links in my signature below. Just makes the conversation convenient

Buy me Coffee, if you feel i was helpful. Email Me here or WhatsApp me with this link for any help with shopify theme customizations or any project in web dev. If this is helpful, please Like and Accept the solution.