When a different variant is selected, the default variant is added to cart

Hi guys, Dave here at UK Aspire vendor (www.ukaspirevendor.co.uk).

We have an issue with variant selection in our store.

Whenever a customer selects a different variant within a product and adds that to their basket, the default variant is added instead.

You can test this by clicking on this product and choosing the 20mg variant.

I would suspect that this is down to some code which hides the quantity selector and add to cart button depending on product tag.

At present, the buttons become available when the product is tagged with ‘InStock, LOWSTOCK, & PRE-ORDER’

I would really appreciate some help here if someone would be so kind.

Here is the full code for our product listing:

{%- comment -%}


THIS IS THE PRODUCT WHEN VIEWED AT PRODUCT LEVEL

{%- endcomment -%}

{%- assign selected_variant = product.selected_or_first_available_variant -%}

{%- if section.settings.enable_image_zoom -%}
{%- endif -%}
{% comment %} ------------------------------------------------------------------------------ PRODUCT META ------------------------------------------------------------------------------

{% endcomment %}

{%- if section.settings.show_share_buttons -%}
{%- capture share_buttons -%}
{%- assign share_url = shop.url | append: product.url -%}
{%- assign twitter_text = product.title | url_param_escape -%}
{%- assign pinterest_description = product.description | strip_html | truncatewords: 15 | url_param_escape -%}
{%- assign pinterest_image = product.featured_media | img_url: ‘1024x’ | prepend: ‘https:’ -%}

{%- endcapture -%} {%- endif -%}
{%- if template.name == 'product' and template != 'product.quick-view' -%}

{{ product.title }}

{%- else -%}

{{ product.title }}

{%- endif -%}

{%- capture product_labels -%}
{%- for tag in product.tags -%}
{%- if tag contains ‘__label:’ -%}
{{ tag | split: ‘__label:’ | last }}
{%- endif -%}

{%- if tag contains ‘__label1:’ -%}
{{ tag | split: ‘__label1:’ | last }}
{%- endif -%}

{%- if tag contains ‘__label2:’ -%}
{{ tag | split: ‘__label2:’ | last }}
{%- endif -%}
{%- endfor -%}

{%- if settings.show_discount -%}
{%- assign savings = 0 -%}

{%- if settings.discount_mode == ‘percentage’ -%}
{%- assign savings = selected_variant.compare_at_price | minus: selected_variant.price | times: 100.0 | divided_by: selected_variant.compare_at_price | round | append: ‘%’ -%}
{%- else -%}
{%- capture savings -%}{{ selected_variant.compare_at_price | minus: selected_variant.price | money_without_trailing_zeros }}{%- endcapture -%}
{%- endif -%}

<span class=“product-label product-label–on-sale” {% unless selected_variant.price < selected_variant.compare_at_price %}style=“display: none”{% endunless %}>{{ ‘collection.product.discount_html’ | t: savings: savings }}
{%- endif -%}
{%- endcapture -%}

{%- if product_labels != blank -%}

{{- product_labels -}}
{%- endif -%}

{%- if section.settings.show_vendor or section.settings.show_sku and selected_variant.sku != blank -%}

{%- if section.settings.show_vendor -%} {%- assign vendor_handle = product.vendor | handle -%} {%- assign collection_for_vendor = collections[vendor_handle] -%}

{%- unless collection_for_vendor.empty? -%}
{{ product.vendor }}
{%- else -%}
{{ product.vendor }}
{%- endunless -%}
{%- endif -%}

{%- if section.settings.show_sku and selected_variant.sku != blank -%}

{{- ‘product.general.sku’ | t -}} {{ selected_variant.sku }}

{%- endif -%}

{%- endif -%}

{%- if section.settings.show_reviews_badge -%}


{%- comment -%}Display a placeholder, to allocate space{%- endcomment -%}

{%- endif -%} {%- if section.settings.show_share_buttons -%}
{{ share_buttons }}
{%- endif -%}

{%- if request.page_type == ‘index’ and section.settings.show_description and product.description != blank and section.settings.description_below_add_to_cart == false -%}

{{ product.description | remove: 'data-section-type="product"' }}
{%- endif -%}

{% comment %}

PRODUCT FORM

{% endcomment %}

{% for tag in product.tags %} {% if tag contains 'COMING SOON' %} {% form 'customer' %} THIS PRODUCT IS COMING SOON.
Sign up for our mailing list to be the first to know when it is released.
We don't spam. We promise.


<img src="[https://i.imgur.com/iFXY9rN.jpg"</button](https://i.imgur.com/iFXY9rN.jpg" {% endform %} {% endif %} {%- endfor -%}

{%- assign color_label = ‘color,colour,couleur,cor,colore,farbe,색,色,カラー,färg,farve’ | split: ‘,’ -%}

{%- form ‘product’, product, class: ‘product-form’ -%}
{%- unless product.has_only_default_variant -%}

{%- for option in product.options_with_values -%} {%- assign downcase_option = option.name | downcase -%} {%- capture option_name -%}{{ section.id }}-{{ product.id }}-{{ forloop.index }}{%- endcapture -%}

{%- assign option_selector_type = ‘select’ -%}

{%- if section.settings.color_mode != ‘block’ and section.settings.color_mode != ‘dropdown’ and color_label contains downcase_option -%}
{%- comment -%}NOTE: even if the merchant is using the mode to display variant images, if ALL variant do not have an associated image, we fallback to color{%- endcomment -%}

{%- assign has_image_attached_to_all_variants = true -%}

{%- for variant in product.variants -%}
{%- unless variant.image -%}
{%- assign has_image_attached_to_all_variants = false -%}
{%- break -%}
{%- endunless -%}
{%- endfor -%}

{%- if section.settings.color_mode == ‘color’ or has_image_attached_to_all_variants == false -%}
{%- assign option_selector_type = ‘color’ -%}
{%- else -%}
{%- assign option_selector_type = ‘variant’ -%}
{%- endif -%}
{%- else -%}
{%- if color_label contains downcase_option -%}
{%- if section.settings.color_mode == ‘block’ -%}
{%- assign option_selector_type = ‘block’ -%}
{%- endif -%}
{%- elsif section.settings.selector_mode == ‘block’ -%}
{%- assign option_selector_type = ‘block’ -%}
{%- endif -%}
{%- endif -%}

{%- case option_selector_type -%} {%- when 'color' -%} {{ option.name }}: {{ option.selected_value }}
{%- for value in option.values -%} {%- assign downcased_value = value | downcase -%} {%- capture color_id -%}{{ option_name }}-{{ forloop.index }}{%- endcapture -%}

{%- assign color_swatch_name = value | handle | append: ‘.png’ -%}
{%- assign color_swatch_image = images[color_swatch_name] -%}

{% render 'icon', icon: 'cross-sold-out' %}
{%- endfor -%}
{%- when 'variant' -%} {{ option.name }}: {{ option.selected_value }}
{%- capture option_name -%}option{{ option.position }}{%- endcapture -%}

{%- for value in option.values -%}
{%- capture variant_swatch_id -%}{{ option_name }}-{{ forloop.index }}{%- endcapture -%}

{%- for variant in product.variants -%}
{%- if variant[option_name] == value and variant.image -%}

{{ variant.image.alt | escape }}

{% render ‘icon’, icon: ‘cross-sold-out’ %}

{%- break -%}
{%- endif -%}
{%- endfor -%}
{%- endfor -%}

{%- when 'block' -%} {{ option.name }}: {{ option.selected_value }}
{%- for value in option.values -%} {%- capture block_swatch_id -%}{{ option_name }}-{{ forloop.index }}{%- endcapture -%}
{{ value }}
{%- endfor -%}
{%- when 'select' -%} {{ option.name }}: {{ option.selected_value }}
{%- render 'icon', icon: 'arrow-bottom' -%}
{%- endcase -%}
{%- endfor -%}
{{ 'product.form.variant' | t }}
{%- else -%} {%- endunless -%}
{{ 'product.form.price' | t }}:
{%- if selected_variant.compare_at_price > selected_variant.price -%} {{ selected_variant.price | times: 1.2 | money_without_trailing_zeros }} {{ selected_variant.compare_at_price | times: 1.2 | money_without_trailing_zeros }} {%- else -%} {{ selected_variant.price | times: 1.2 | money_without_trailing_zeros }} {%- endif -%}
{{ selected_variant.unit_price | times: 1.2 | money_without_trailing_zeros }} /

{%- if selected_variant.unit_price_measurement.reference_value != 1 -%}
{{ selected_variant.unit_price_measurement.reference_value }}
{%- endif -%}

{{ selected_variant.unit_price_measurement.reference_unit }}

{%- if section.settings.show_taxes_included -%}
{%- if shop.taxes_included or shop.shipping_policy.body != blank -%}

{%- if shop.taxes_included -%} {{ 'product.general.include_taxes' | t }} {%- endif -%}

{%- if shop.shipping_policy.body != blank -%}
{{ ‘product.general.shipping_policy_html’ | t: link: shop.shipping_policy.url }}
{%- endif -%}

{%- endif -%} {%- endif -%}

{% comment %}


CODE REGARDING BULLET POINT SHOWS HERE

{% endcomment %}

{% for tag in product.tags %}
{% if tag == ‘__label:PRE-ORDER’ %}
PRE-ORDER
{% else %}

{% if tag == ‘InStock’ -%}
AVAILABLE TO ORDER
{% else %}

{% if tag == ‘__label1:COMING SOON’ %}
COMING SOON
{% else %}

{% if tag == ‘LOWSTOCK’ %}
LOW STOCK
{% else %}

{% if tag == ‘NIS’ %}
OUT OF STOCK
{% else %}

{% if tag == ‘__label:DISCONTINUED’ %}
DISCONTINUED
{% else %}

{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}

{% comment %}


CODE REGARDING BULLET POINT ENDS HERE

{% endcomment %}

{% for tag in product.tags %}
{% if tag contains ‘InStock’ %}

{%- if product.template_suffix != ‘contact’ -%}
{%- if section.settings.show_quantity_selector -%}

{{ 'product.form.quantity' | t }}:
{%- render 'icon', icon: 'arrow-bottom' -%}
{%- else -%} {%- endif -%} {%- endif -%} {% endif %} {%- endfor -%}

{% for tag in product.tags %}
{% if tag contains ‘PRE-ORDER’ %}

{%- if product.template_suffix != ‘contact’ -%}
{%- if section.settings.show_quantity_selector -%}

{{ 'product.form.quantity' | t }}:
{%- render 'icon', icon: 'arrow-bottom' -%}
{%- else -%} {%- endif -%} {%- endif -%} {% endif %} {%- endfor -%}

{% for tag in product.tags %}
{% if tag contains ‘LOWSTOCK’ %}

{%- if product.template_suffix != ‘contact’ -%}
{%- if section.settings.show_quantity_selector -%}

{{ 'product.form.quantity' | t }}:
{%- render 'icon', icon: 'arrow-bottom' -%}
{%- else -%} {%- endif -%} {%- endif -%} {% endif %} {%- endfor -%}

{%- if product.handle contains ‘50ml’ %}
PLEASE NOTE: WE DO NOT INCLUDE NIC SHOTS.

FOR THIS LIQUID PLEASE PURCHASE 1X 18MG <A HREF=“https://www.ukaspirevendor.co.uk/products/nic-nic-18mg-nic-shot”" target=“_blank”>NIC SHOT TO MAKE 3MG.
{% elsif product.handle contains ‘80ml’ %}

PLEASE NOTE: WE DO NOT INCLUDE NIC SHOTS.

FOR THIS LIQUID PLEASE PURCHASE 2X 18MG + ADD 1.6 <A HREF=“Nic Shots | 18mg 10ml | UK Aspire Vendor Nicotine Shots”" target=“_blank”>NIC SHOTS TO MAKE 3MG.
{% elsif product.handle contains ‘100ml’ %}

PLEASE NOTE: WE DO NOT INCLUDE NIC SHOTS.

FOR THIS LIQUID PLEASE PURCHASE 2X 18MG <A HREF=“Nic Shots | 18mg 10ml | UK Aspire Vendor Nicotine Shots”" target=“_blank”>NIC SHOTS TO MAKE 3MG.
{% elsif product.handle contains ‘200ml’ %}

PLEASE NOTE: WE DO NOT INCLUDE NIC SHOTS.

FOR THIS LIQUID PLEASE PURCHASE 4X 18MG <A HREF=“Nic Shots | 18mg 10ml | UK Aspire Vendor Nicotine Shots”" target=“_blank”>NIC SHOTS TO MAKE 3MG.
{% endif %}


{% for tag in product.tags %}
{% if tag contains ‘InStock’ %}

{%- if product.template_suffix != 'contact' -%} {%- if selected_variant.available -%} {% if tag contains 'PREORDER' %} {{ 'product.form.pre_order' | t }} {%- else -%} {{ 'product.form.add_to_cart' | t }} {%- endif -%} {%- else -%} {{ 'product.form.sold_out' | t }} {%- endif -%}

{%- if section.settings.show_payment_button -%}
{{ form | payment_button }}
{%- endif -%}
{%- else -%}
{{ ‘product.form.contact_us’ | t }}
{%- endif -%}

{% endif %} {%- endfor -%}

{% for tag in product.tags %}
{% if tag contains ‘LOWSTOCK’ %}

{%- if product.template_suffix != 'contact' -%} {%- if selected_variant.available -%} {% if tag contains 'PREORDER' %} {{ 'product.form.pre_order' | t }} {%- else -%} {{ 'product.form.add_to_cart' | t }} {%- endif -%} {%- else -%} {{ 'product.form.sold_out' | t }} {%- endif -%}

{%- if section.settings.show_payment_button -%}
{{ form | payment_button }}
{%- endif -%}
{%- else -%}
{{ ‘product.form.contact_us’ | t }}
{%- endif -%}

{% endif %} {%- endfor -%}

{% for tag in product.tags %}
{% if tag contains ‘PRE-ORDER’ %}

{%- if product.template_suffix != 'contact' -%} {%- if selected_variant.available -%} {% if tag contains 'PREORDER' %} {{ 'product.form.pre_order' | t }} {%- else -%} {{ 'product.form.add_to_cart' | t }} {%- endif -%} {%- else -%} {{ 'product.form.sold_out' | t }} {%- endif -%}

{%- if section.settings.show_payment_button -%}
{{ form | payment_button }}
{%- endif -%}
{%- else -%}
{{ ‘product.form.contact_us’ | t }}
{%- endif -%}

{% endif %} {%- endfor -%} {%- endform -%}

{%- if request.page_type == ‘index’ and section.settings.show_description and product.description != blank and section.settings.description_below_add_to_cart -%}

{{ product.description }}
{%- endif -%}

{%- if section.settings.show_share_buttons -%}

{{ 'product.general.share' | t }} {{ share_buttons }}
{%- endif -%}

{%- if section.settings.show_payment_button and product.selected_or_first_available_variant.available == false -%}

#shopify-section-{{ section.id }} .shopify-payment-button { display: none; }

{%- endif -%}

{% comment %}

Product Data. This must be outputted for all products (including home page).

IMPORTANT: THIS CODE IS VITAL. DO NOT EDIT IT NOT REMOVE IT. MAKE SURE TO KEEP
THE EXACT SAME ATTRIBUTES.

{% endcomment %}

{% comment %}


DAVE NOTES - I’M HIDING THIS SECTION BECAUSE IF A VARIANT IS SELECTED THE INVENTORY NUMBERS WILL RETURN


END HIDDEN CODE HERE

{% endcomment %}

Hi there @UK_Aspire_Vendo !

Don here from Shopify.

Thanks for the info and store link here.

In order to get this investigated further, I’ll just need to send an email out to the address we have on file for you here so we can escalate this securely.

I’ll be sending that out shortly, so if you can just reply there we can use this to verify your identity and proceed to work on this securely.

All the best!

Regards,

Don

Disregard my reply. I am trying to delete it.