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 %}
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 %}
dbuglab
2
Hi @EMS_Co
Can you please try {% if variant.metafields.my_fields.preorders != blank %} Test {% endif %}
EMS_Co
3
Variants metafields not working in options loop..
Like:
{% for value in option.values %}
dbuglab
4
Hi @EMS_Co
This code will not work here.
EMS_Co
5
Any idea how it will work in option variants?
dbuglab
6
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.
dbuglab
7
{% 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 %}
EMS_Co
8
EMS_Co
9
It is working but it assigns class to all which is not true.
dbuglab
10
Hi @EMS_Co
Can you please let me which are true or which aren’t ?
EMS_Co
12
Screenshot: Screenshot by Lightshot
X/S > true
S/M > false
M/L > false
dbuglab
13
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.
EMS_Co
14
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.