EMS_Co
1
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 %}
Jason
2
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”.
EMS_Co
3
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.
EMS_Co
4
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 %}
EMS_Co
5
Hi Jason Are you there?
Plz help me.
Jason
6
You have code that is expecting a value to explicitly equal true.
{% if variant.metafields.my_fields.preorders == true %}
So my questions are:
- What is the actual value of that metafield. Do you have a screenshot?
- What is the type of the metafield.
- 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.
EMS_Co
7
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 %}
EMS_Co
8
I am stuck in this task for many days I do not understand one thing why this value option is not working in loop.