Why is the wrong variant being added to my cart?

This is the code for the selection variant:

{% unless product.has_only_default_variant %} {% for option in product.options_with_values %} {% assign get_opt_nm = option.name | downcase %}
{{ option.name }} {% for value in option.values %} {{ value }}{% endfor %}
{% endfor %} {% endunless %}{% for variant in product.variants %} {{ variant.title }}{% endfor %}
{% assign check_sz = 0 %} {% assign check_clr = 0 %} {% unless product.has_only_default_variant %} {% for option in product.options_with_values %} {% if option.name == ‘Size’ %} {% assign check_sz = 1 %} {% endif %} {% if option.name == ‘Color’ %} {% assign check_clr = 1 %} {% endif %} {% endfor %} {% endunless %} {% if check_sz == 1 %}{% render ‘swatch’ with ‘Size’ as swatch %} {% if settings.size_guide_title != blank or settings.size_guide_content != blank %}
Size Guide
{% endif %}
{% endif %}
{% if check_clr == 1 %}{% render ‘swatch’ with ‘Color’ as swatch %}
{% endif %}

When I select medium size

The small size being added to the cart

This is the store: https://greenerymarket.com/

There’s actually a hidden select inside your collection page form, I’ve unhidden it in the screenshot above. As you can see the hidden form contains the variantID (which is what will be added to cart) as the value, rather than the option name like the selector above it. Usually on the product page, when changing the visible selector, the hidden once will be changed by some javascript. This javascript isn’t present, or isn’t working on collection pages.