Hi there,
I know Shopify allows us to set up multiple variants per product, including size and colour. However we decided to have individual product pages for each size available of a single product.
I was able to implement a piece of code (see below) to show product labels for each product size or option. It works really well, however I can’t seem to find a way to re-order these labels alphabetically (A-Z or 0-9). So if you read this and know how to fix this, pleeeeeeeease let me know as I’ve spent way too much time trying to figure this out by myself.
Example: https://orka.ca/products/packout%E2%84%A2-tool-box if you look under the “Also Available In”, these are the labels I am referring to that are showing different options for this product. I want them to be ordered alphabetically, A to Z.
Another example: https://orka.ca/products/nvent-raychem-frostguard-freeze-protection-plug-in-kit-12-ft-model-fg112p if you look under the “Also Available In”, these are the labels I am referring to that are showing the different sizes for this product. I want them to be ordered numerically, 0 to 9.
Here my code to generate these labels. I basically create a product tag (i.e: len-milwaukee-packout) and assign it to all products I want to link together, and then use the metafield “product_size” I created to assign the name I want to display in the label.
{%- assign tag_len = "BLANK" -%}
{%- for tag in product.tags -%}
{%- assign tag_len_prefix = tag | slice: 0, 4 -%}
{%- if tag_len_prefix == "len-" -%}
{%- assign tag_len = tag -%}
{%- break -%}
{%- endif -%}
{%- endfor -%}
{%- unless tag_len == "BLANK" -%}
{%- assign vendor_handle = product.vendor | handle -%}
{%- if collections[vendor_handle].products.size > 0 -%}
{%- assign len_products_total = 0 -%}
{%- capture products_len_output -%}
{%- paginate collections[vendor_handle].products by 2000 -%}
{%- for len_product in collections[vendor_handle].products -%}
{%- if len_product.tags contains tag_len -%}
{%- unless len_product.id == product.id -%}
{%- assign len_products_total = len_products_total | plus: 1 -%}
{{ len_product.metafields.global.product_size }}
{%- endunless -%}
{%- endif -%}
{%- endfor -%}
{%- endpaginate -%}
{%- endcapture -%}
{%- endif -%}
{%- endunless -%}
{%- if len_products_total > 0 -%}
**Also Available In:**
{{ products_len_output }}
{%- endif -%}
I hope this makes sense. Any help would be much appreciated here ![]()