Need help with adding metafields to product variants?

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 %}

{% for value in option.values %}
        
                
       

{% endfor %}

What is the actual value and type of that metafield? If it’s a string, the value of true is not the same as “true”.

Thx for reply but sorry jason I don’t understand what you want to say. I can get some more information about it because it is very important for me.

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,
my work is stuck plz help.

{% 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 Jason Are you there?
Plz help me.

You have code that is expecting a value to explicitly equal true.

{% if variant.metafields.my_fields.preorders == true %}

So my questions are:

  1. What is the actual value of that metafield. Do you have a screenshot?
  2. What is the type of the metafield.
  3. If you can’t answer 2, perhaps let us know how you created the metafield. A screenshot will help.

I want you to rule out that the value isn’t in fact “true”.

If it is “true” then your code would need to be:

{% if variant.metafields.my_fields.preorders == "true" %}

This doesn’t mean that’s the issue but but once we know exactly what the value is we can move on.

This is my Update code.

{% 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 %}

I am stuck in this task for many days I do not understand one thing why this value option is not working in loop.