How do I change the default variant to the cheapest Price?

shipped
New Member
6 0 0

Hey guys,

 

I need help regarding the variant selector. Right now it automatically selects the first variant, while I want it to be the cheapest one.

 

Thats the code of the variant wrapper.

 

<div class="variant-wrapper variant-wrapper--{{ settings.variant_type }} js">
  <label class="variant__label{% if option.name == 'Default' or option.name == 'Title' %} hidden-label{% endif %}{% unless settings.variant_labels_enable %} hidden-label{% endunless %}"
    for="SingleOptionSelector-{{ section_id }}-option-{{ forloop.index0 }}">
    {{ option.name }}
  </label>
  <div class="variant-input-wrap" data-index="option{{ forloop.index }}" data-handle="{{ option.name | handleize }}">
    <select
      class="variant__input-{{ section_id }}"
      id="SingleOptionSelector-{{ section_id }}-option-{{ forloop.index0 }}"
      data-index="option{{ 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 %}
        <option
          value="{{ value | escape }}"
          {% if option.selected_value == value %} selected="selected"{% endif %}
          {% unless variant_label_state %} disabled="disabled"{% endunless %}
          name="{{ option.name }}"
          class="variant-input"
          data-index="option{{ forloop.index }}">
          {{ value }}
        </option>
      {%- endfor -%}
    </select>
  </div>
</div>

 Any help is greatly appreciated!

 

Store: shipped.de

password: veirao

0 Likes