How can I correctly sort the size variants of my product?

Topic summary

Problem: Product size variants display in incorrect order (not sequential like 42, 44, 46), affecting stores with thousands of products where manual reordering is impractical.

Initial Suggestion: Shopify’s built-in “reorder variants” feature allows drag-and-drop sorting per product, but this manual approach is unrealistic for stores with 1,000-3,000+ products.

Community Need: Multiple users confirm experiencing this issue and seek a global/automated solution using Liquid code or other methods to sort variants numerically or alphabetically across all products.

Working Solution (billnyescienceg):

  • Create a global size order array in variant-picker.liquid (line 2)
  • List ALL sizes in desired sequence
  • Use a {% for size in size_order %} loop (lines 20-36) to iterate through the predefined order
  • Match and display sizes from the product options in the specified sequence
  • Adjust option position number (line 19) based on where size appears in your variant structure

Key Limitation: Sizes not included in the global array won’t display. The solution requires modifying theme code and maintaining the size list as inventory changes.

Summarized with AI on October 30. AI used: claude-sonnet-4-5-20250929.

Hi there :slightly_smiling_face:
would be happy if someone can help me here!

product sizes are not displayed in the correct order.
I wanted to sort product options swatches.
The size options should be sorted like 42,44,46…

this is how it looks like currently:

I tried something with {.. | sort %}, but it didnt work :disappointed_face:

this is the code:

{% capture colorSwatches %}

{% assign found_option = false %}
{% assign is_color = false %}
{% assign is_size = false %}
{% assign option_index = 0 %}

{% for option in product.options %}
    {% if option == swatch %}
      {% assign found_option = true %}
      {% assign option_index = forloop.index0 %}
      {% assign downcased_option = swatch | downcase %}
      {% if downcased_option contains 'color' or downcased_option contains 'colour' or downcased_option contains 'couleur' or downcased_option contains 'farbe' %}
        {% assign is_color = true %}
      {% endif %}
	{% if downcased_option contains 'size' or downcased_option contains 'taille' or downcased_option contains 'tamaño' or downcased_option contains 'größe' %}
        {% assign is_size = true %}
      {% endif %}
    {% endif %}
{% endfor %}

  

    

    {% assign values = ''  %}
    {% for variant in product.variants %}
      {% assign value = variant.options[option_index]  %}
      {% assign var_index = forloop.index0  %}
      {% unless values contains value %}
        {% assign values = values | join: ','  %}
        {% assign values = values | append: ',' | append: value %} 
        {% assign values = values | split: ','  %}
        {% assign colorname = value | handleize %}

    
          

            
            {% if is_color %}
            {% if settings.sw_color_type == "color" %}
            
            {{ value }}
            {% else %}
            
            {{ value }}
            {% endif %}
            {% else %}
                        	
            {% endif %}
          

      {% endunless %}
    {% endfor %}
  

{% endcapture %}
{{colorSwatches | strip_newlines | remove: "  " | remove: "	" }}
2 Likes

Hey, @pretent

Luckily there is a much easier solution that requires no coding. When you go into your product, there is an option to reorder your variants! I’ve attached a screenshot to show you:

From the reorder variants screen you can drag them in whichever order you like! I hope this helps. If there is anything else I can help you with, please let me know.

1 Like

Hey Dirk,
thx for your reply :slightly_smiling_face:

Yeah i know this kind of solution but, we have imported over 3000 product with random size sequence :disappointed_face:
Cant reorder them manually

Hey!

That is a great solution if you have 15-20 products. But in a move to make more money we got hit by a strike of genius one day sitting in the office and realized that having more products would lead to having more sales. To our amazement that worked pretty well, but 3,000 plus products later it is unrealistic to think we can go product by product and reorder sizing. Is there a global solution to organize variants utilizing numeration or alphabetization?! I’ve talked to a least two dozen shopify users that have this same issue.

5 Likes

Hi, just wondering if you ever found a solution other than a manual sorting? Cheers

Hi, Just wondering too, if there some way to do this from liquid or something. Cause I have more than 1000 products.

Any update on this issue? I am running into the same problem.

3 Likes

I know this thread is old, but I have a solution that I believe will work.

This is my variant-picker.liquid file.

The important code:

  • line 2 - create a global order for your sizes. All sizes need to be present in this list. Any sizes not present in this list will not display

  • lines 20-36 - {% for size in size_order %} - This block iterates over all the sizes in line 2. For each size, it looks for the value in the options list. When it finds a match, it displays the size option on the page.

Note: On line 19, I specify that this handling is only for the option in position 2. This is because in my site, I display color first, size second. You would need to adjust this value if the relevant selector is in a different position.

Hopefully this helps someone else. If you’re reading this, and you find any issues with my approach, I’d appreciate feedback!

{% comment %} Change this to the desired list {% endcomment %}
{% assign size_order = "XS,S,M,L,XL,XXL,75C,75D,75E,80C,80D,80E,85C,85D,85E" | split: "," %}

{% for option in product.options_with_values %}
  

    {% comment %} Other unrelated code... {% endcomment %}

    {%- if settings.variant_style == 'dropdown' -%}  

      {% comment %} Other unrelated code... {% endcomment %}

    {%- else -%}
      
    {%- endif -%}
    
  

{% endfor %}