Liquid, JavaScript, themes, sales channels
To continue receiving payouts, you need to secure your account by turning on two-step authentication. If two-step authentication is not turned on your payouts will be paused. Learn more
I want to change the variant when clicking on the variant image I have found the solution but its only works in select and option but in my theme, I am using input type radio button instead of the select option button.
------------------------------------------Here is my code for the variant-----------------------------------------------------------
<!-- productOption.liquid -->
{%- if section.settings.product_selector == 'radio' -%}
{%- assign isColor = false -%}
{%- assign optionName = option.name | handleize -%}
{%- if optionName contains 'colo' -%}
{%- assign isColor = true -%}
{%- endif -%}
<fieldset class="single-option-radio"
name="{{ option.name | handleize }}"
id="ProductSelect-option-{{ forloop.index0 }}">
{%- assign option_index = forloop.index -%}
{%- for value in option.values -%}
{%- assign variant_label_state = true -%}
{%- if product.options.size == 1 -%}
{%- unless product.variants[forloop.index0].available -%}
{%- assign variant_label_state = false -%}
{%- endunless -%}
{%- endif -%}
{%- for variant in product.variants %}
{%- assign vOption = 'option' | append: option_index -%}
{%- if value == variant[vOption] -%}
{%- assign currenVariant = variant -%}
{%- break -%}
{%- endif -%}
{%- endfor -%}
{%- assign hasImage = false -%}
{%- if isColor and currenVariant.image -%}
{%- assign hasImage = true -%}
{%- endif -%}
<input type="radio"
{%- if option.selected_value == value -%} checked="checked"{%- endif -%}
{%- unless variant_label_state -%} disabled="disabled"{%- endunless -%}
value="{{ value | escape }}"
data-index="option{{ option_index }}"
name="{{ option.name | handleize }}"
class="single-option-selector-{{ section.id }} single-option-selector__radio{% unless variant_label_state %} disabled{% endunless %}"
id="ProductSelect-option-{{ option.name | handleize }}-{{ value | escape }}">
<label {% if hasImage %}data-tooltip="true" title="{{ value | escape }}" style="background-image:url({{currenVariant.image.src | img_url:'100x'}})"{% endif %}
for="ProductSelect-option-{{ option.name | handleize }}-{{ value | escape }}"{% unless variant_label_state %} class="disabled"{% endunless %}>
{%- unless hasImage -%}{{ value | escape }}{%- endunless -%}
</label>
{%- endfor -%}
</fieldset>
{%- else -%}
<select class="single-option-selector single-option-selector-{{ section.id }} product-form__input"
id="SingleOptionSelector-{{ forloop.index0 }}"
data-name="{{ option.name }}"
data-index="option{{ forloop.index }}">
{%- for value in option.values -%}
<option value="{{ value | escape }}"{% if option.selected_value == value %} selected="selected"{% endif %}>{{ value }}</option>
{%- endfor -%}
</select>
{%- endif -%}
---------------------------------------------------Variant Code Ended-----------------------------------------------------------
-----------------------------------------------------------here is the js to change variants---------------------------------------------------
https://help.shopify.com/en/manual/online-store/themes/os/customize/select-variants-click----------------------------------------------------------------------------------------------------
Thanks In Advance if someone helps me to resolve this issue.
Can you please provide store URL ?
actually, I am working on a copy and don't want to make it publish . You can see the Brooklyn theme variant style it is the same as my store. Waiting for Your response
Learn these 5 things I had to learn the hard way with starting and running my own business
By Kitana Jan 27, 2023Would you love to unleash the unbridled power of the Google Shopping Channel into your sho...
By Gabe Jan 6, 2023How can you turn a hobby into a career? That’s what Emmanuel did while working as a wa...
By Skye Dec 30, 2022