Manage Soldout with multiple variants - liquid

Topic summary

A Shopify store owner is experiencing an inventory display issue with products that have multiple color and size variants. When a specific size (e.g., M) is out of stock in one color (blue), the system incorrectly shows that same size as unavailable across all other colors (black, gray).

Attempted Solution:
The user wants to dynamically update size availability whenever a color is selected but hasn’t found a working implementation.

Code Context:
They’ve shared their variant swatch code (written in Liquid), which handles color/size option rendering with various display styles (color swatches, gallery, radio buttons, rectangles). The code appears partially corrupted or reversed in sections.

Response:
One commenter suggested using Apimio’s Product Information Management (PIM) system, which integrates with Shopify to manage variant-level product information and automatically sync inventory data.

Status: The discussion remains open with no confirmed resolution to the core inventory display logic problem.

Summarized with AI on November 19. AI used: claude-sonnet-4-5-20250929.

I have a Shopify store that has products with multiple Colors and multiple Sizes each. The issue with this is that for example, if I have a product that has just the size M in color blue out of stock it will display as out of stock also the other color variants like the size M for the colors black and gray. My idea was to find a way to update the size quantities every time the color is changed but I really don’t know how, I’ve tried in different ways but none of them even remotely worked, also I don’t know if there’s an easier way to solve this problem.

This is the code of the product variant swatches, let me know if something isn’t clear or if I have to add something else, thank you all in advance.

{% comment %}
    Set the extension of your color files below. Use 'png', 'jpeg', 'jpg' or 'gif'.
{% endcomment %}
{% assign file_extension = 'png' %}
{% capture variantsswatch %} {% endcapture %}
{% if swatch == "Color" %}
    {% capture variantsswatch %}{{ 'products.variants.color' | t }}{% endcapture %}
{% elsif swatch == "Size" %}
    {% capture variantsswatch %}{{ 'products.variants.size' | t }}{% endcapture %}
{% else %}
    {% capture variantsswatch %}{{ swatch }}{% endcapture %}
{% endif %}

{% if swatch == blank %}
    <div class="swatch error">
        <p>You must include the snippet swatch.liquid with the name of a product option.</p>
        <p>Use: <code>{% raw %}{% include 'swatch' with 'name of your product option here' %}{% endraw %}</code></p>
        <p>Example: <code>{% raw %}{% include 'swatch' with 'Colore' %}{% endraw %}</code></p>
    </div>
{% else %}
    {% assign found_option = false %}
    {% assign is_color = false %}
    {% assign option_index = 0 %}
    {% assign indexChild = 0 %}

    {% for option in product.options %}
        {% if option == swatch %}
            {% assign found_option = true %}
            {% assign option_index = forloop.index0 %}
            {% assign indexChild = forloop.index %}
            <style rel="stylesheet" type="text/css">
                .proVariants .selector-wrapper:nth-child({{ indexChild }}){display: none;}
                .maxus-productdetail__options:not(:last-child) {margin-right: 20px;}
            </style>
            {% assign downcased_option = swatch | downcase %}
            {% if downcased_option contains 'colore' or downcased_option contains 'colour' %}
                {% assign is_color = true %}
            {% endif %}
        {% endif %}
    {% endfor %}

    {% unless found_option %}

    {% else %}
        <div class="maxus-productdetail__options{% unless section.settings.spd_style == "pd_style2" %} {% endunless %}">
            <div class="{% if settings.swatch_style == "sw_radio1" or settings.swatch_style == "sw_radio2" %}   swatch_radio1 {% elsif settings.swatch_style == "sw_radio3" or settings.swatch_style == "sw_radio4" %} swatch_radio3 {% elsif settings.swatch_style == "sw_rectangle1" or settings.swatch_style == "sw_rectangle2" or settings.swatch_style == "sw_gallery"  %} swatch_rectangle1 {% endif %}swatch clearfix {% if settings.po_style == "po_swatchs" %} align-center flex engoc-flex-wrap{% endif %}" data-option-index="{{ option_index }}">
                <p class="text-uppercase title_variant">{{ variantsswatch }} </p>
                {% assign values = '' %}

                {% for variant in product.variants %}
                    {% assign value = variant.options[option_index] %}
                    {% unless values contains value %}
                        {% assign values = values | join: ',' %}
                        {% assign values = values | append: ',' | append: value %}
                        {% assign values = values | split: ',' %}
                        <div data-value="{{ value | escape }}"  data-style="square" class="maxus-color none {% if is_color %}color {% endif %}{{ value | handle }} {% if variant.available %}available{% else %}soldout{% endif %}" {% if variant.available %}{% else %}data-toggle="tooltip" data-placement="top"  data-original-title="Sold Out"{% endif %}>
                            <input id="swatch-{{ option_index }}-{{ value | handle }}" type="radio" name="option-{{ option_index }}" value="{{ value | escape }}"{% if forloop.first %} checked{% endif %} {% unless variant.available %}disabled{% endunless %} />
                            {% if is_color %}
                                {% if settings.swatch_style == "sw_radio1" or settings.swatch_style == "sw_radio3"  %}
                                    <label class="radio_style1" for="swatch-{{ option_index }}-{{ value | handle }}">
                                        <label class="color_style1" for="swatch-{{ option_index }}-{{ value | handle }}">
                                        </label>
                                        <span class="text_color">{{ value }}</span>
                                    </label> 
                                {% elsif settings.swatch_style == "sw_radio2"  %}
                                    <div class="radio_style2" data-toggle="tooltip" data-placement="top" data-original-title="{{value}}">
                                        <label class="color_style2" for="swatch-{{ option_index }}-{{ value | handle }}" style="background-image: url({{ variant.image.src | product_img_url: 'grande' }}); background-size: cover;">
                                        </label>
                                    </div>
                                {% elsif settings.swatch_style == "sw_rectangle1"  %}
                                        <label class="rectangle_style1" for="swatch-{{ option_index }}-{{ value | handle }}">
                                            <span class="text_rec">{{ value }}</span>
                                        </label>
                                {% elsif settings.swatch_style == "sw_gallery"  %}
                                    <div class="swatch_gallery">
                                        <label class="bg_image" for="swatch-{{ option_index }}-{{ value | handle }}" style="background-color: {{ value | split: ' ' | last | handle }}; background-image: url({{ value | handle | append: '.' | append: file_extension | file_url }}); background-size: cover;">
                                        </label>
                                    </div> 
                                {% elsif settings.swatch_style == "default" or settings.swatch_style == "sw_radio4" or settings.swatch_style == "sw_rectangle2"   %}
                                    <div class="  border-color ">
                                        <label class="link_color" for="swatch-{{ option_index }}-{{ value | handle }}" style="background-color: {{ value | split: ' ' | last | handle }}; background-image: url({{ value | handle | append: '.' | append: file_extension | file_url }}); background-size: cover;">
                                        </label>
                                    </div> 
                                {% endif %}
                            {% else %}
                                {% if settings.swatch_style == "sw_radio1" or settings.swatch_style == "sw_radio2" or settings.swatch_style == "sw_radio3" or settings.swatch_style == "sw_radio4" %}
                                    <label class="radio_style1" for="swatch-{{ option_index }}-{{ value | handle }}">
                                        <label class="color_style1" for="swatch-{{ option_index }}-{{ value | handle }}" >
                                        </label>
                                        <span class="text_color">{{ value }}</span>
                                    </label> 
                                {% elsif settings.swatch_style == "sw_rectangle1" or settings.swatch_style == "sw_rectangle2" or settings.swatch_style == "sw_gallery" %}
                                    <label class="rectangle_style1" for="swatch-{{ option_index }}-{{ value | handle }}">
                                        <span class="text_rec">{{ value }}</span>
                                    </label>
                                {% elsif settings.swatch_style == "default" %}
                                    <label class="variant_other" for="swatch-{{ option_index }}-{{ value | handle }}" >
                                        {{ value }}
                                    </label>
                                {% endif %}
                            {% endif %}
                        </div>
                    {% endunless %}
                <script>
                    jQuery('.swatch[data-option-index="{{ option_index }}"] .{{ value | handle }}').removeClass('soldout').addClass('available').find(':radio').removeAttr('disabled');
                </script>
                {% endfor %}
            </div>
        </div>
    {% endunless %}
{% endif %}

Hi, Managing different product variants and their stock levels on Shopify can indeed be tricky, but don’t worry, there’s a straightforward solution. Apimio’s Product Information Management (PIM) system can help you manage product information of each product. The changes are automatically integrated into the Shopify store. You can visit https://apimio.com/integrations/shopify-pim/ to understand how Apimio’s PIM helps integration with Shopify. You can save yourself all this effort.