Why isn't my variant meta field class working in my code?

Hello Guys Plz help

I have created a meta fields I am adding a class for the variants but it is not working, can you guys help me in solving this.

Code: {% if variant.metafields.my_fields.preorders == true %} Test {% endif %}

This is my complete code can you tell me where i am wrong i have to add a class when my variants fields are true,

{% comment %}
  Display options for a product

   product

   selected_variant

   style
{% endcomment %}

{% assign hide_select_a11y = "" %}

{% if style == 'radio' %}
  {% assign hide_select_a11y = "tabindex='-1'" %}
{% endif %}
{%- capture form_id -%}{% increment form_id %}{%- endcapture -%}

  
  

  {% for option in product.options_with_values %}
    {% assign show_swatches = false %}
    {% if settings.swatches_enable %}
      {%- assign swatch_trigger = settings.swatches_swatch_trigger | strip | downcase -%}
      {% assign option_name = option.name | downcase %}
      {% if option_name == swatch_trigger %}
        {% assign show_swatches = true %}
        {% assign swatch_option_key = 'option' | append: forloop.index %}
      {% endif %}
    {% endif %}

    {% if style == 'select' and show_swatches == false %}
      

        

          
          
          {% include 'icon-library', id: 'icon-chevron-down-small' %}
        

      

    {% elsif style == 'radio' or show_swatches == true %}
      
    {% endif %}
  {% endfor %}

Hi @EMS_Co

Can you please try {% if variant.metafields.my_fields.preorders != blank %} Test {% endif %}

Variants metafields not working in options loop..
Like:

{% for value in option.values %}

Hi @EMS_Co
This code will not work here.

Any idea how it will work in option variants?

Hi @EMS_Co

Can you please share website URL and explain this in which option you want this ?

For now I made some changes in your code it will make changes over all the options.

{% comment %}
Display options for a product

@Anonymous product

@Anonymous selected_variant

@Anonymous style
{% endcomment %}

{% assign hide_select_a11y = “” %}

{% if style == ‘radio’ %}
{% assign hide_select_a11y = “tabindex=‘-1’” %}
{% endif %}
{%- capture form_id -%}{% increment form_id %}{%- endcapture -%}

{% assign varr = “” %}

<select name=“id” data-variants {{ hide_select_a11y }} class=“form-options no-js-required”>
{% for variant in product.variants %}

{% if variant.metafields.my_fields.preorders == true %}{% assign varr = “preorder_pro” %} {% endif %}

{%- capture option_content -%}
{%- if variant.available -%}
{{ variant.title }} - {{ variant.price | money }}
{%- else -%}
{{ variant.title }} - {{ ‘product.status.sold_out’ | t }}
{%- endif -%}
{%- endcapture -%}

{{ option_content | strip_newlines }} {% endfor %}

{% for option in product.options_with_values %}
{% assign show_swatches = false %}
{% if settings.swatches_enable %}
{%- assign swatch_trigger = settings.swatches_swatch_trigger | strip | downcase -%}
{% assign option_name = option.name | downcase %}
{% if option_name == swatch_trigger %}
{% assign show_swatches = true %}
{% assign swatch_option_key = ‘option’ | append: forloop.index %}
{% endif %}
{% endif %}

{% if style == ‘select’ and show_swatches == false %}

{{ option.name }} {% include 'icon-library', id: 'icon-chevron-down-small' %}
{% elsif style == 'radio' or show_swatches == true %} {% assign optionIndex = forloop.index0 %} {% if show_swatches %} {{ option.name }}: {{ option.selected_value }} {% else %} {{ option.name }} {% endif %}
{% for value in option.values %}
{% if show_swatches %} {% assign use_variant_images = false %} {% if settings.swatches_option_style == 'variant_image' %} {% assign use_variant_images = true %} {% endif %} {% assign use_aspect_ratio = false %} {% if settings.swatches_shape == 'square' %} {% assign use_aspect_ratio = true %} {% endif %} {% capture swatch_styles %} {% include 'swatch-styles', color_name: value, use_variant_images: use_variant_images, swatch_product: product, swatch_option_key: swatch_option_key, swatch_size: settings.swatches_product_page_size, use_aspect_ratio: use_aspect_ratio, %} {% endcapture %}
{% else %} {{ value }} {% endif %}
{% endfor %}
{% endif %} {% endfor %}

Here is my Site link
https://6gz5saqazh8tmjw3-6665142362.shopifypreview.com/collections/clothing/products/belted-mohair-coat

It is working but it assigns class to all which is not true.

Hi @EMS_Co
Can you please let me which are true or which aren’t ?

https://prnt.sc/238wgd3

XS > true

S/M > false

M/L > false

Screenshot: Screenshot by Lightshot

X/S > true
S/M > false
M/L > false

Hi @EMS_Co

It will take some time and have to add some custom code as well.
It would be great if you can share me admin details of your store.

I’m sorry sir for this but I don’t have permission to assign access, If you can do something with Anydesk then I will be very happy for me.