Changing unit values based on Variant Options

irenejean
New Member
13 0 0

Hi there, 

I'm trying to display unit prices for our products. (We don't have that option to do that in our store because we are based in the US.) 

The color variants come in packs of 12 or 18 units. 

For example: A user wants the pink in a case size that contains 18. The option is called Size and the name is B18. 

Below is as far as I got in the code, if someone could please let me know what I'm doing wrong it would be amazing! I'm only able to get all products to divide by 12. 

 

{% assign twelve = false %}
{% assign eighteen = false %}
{% assign unit = '12' %}

{% for value in option.values %}
{% if selected_value == 'B18' %}
{% assign eighteen = true %}
{% assign unit = '18' %}
{% endif %}
{% endfor %}

.......

<div class="product-price product-price--large" data-price-wrapper>
<span class="{% if current_variant.compare_at_price > current_variant.price %}product-price__reduced{% endif %}" data-product-price>
<span class="theme-money">{{ current_variant.price | divided_by: unit| money }}</span>
</span>

{% if product.compare_at_price_max > product.price %}
<span class="visually-hidden" data-compare-text>{{ 'products.product.regular_price' | t }}</span>
<span class="product-price__compare {% unless current_variant.compare_at_price > current_variant.price %}hide{% endunless %}" data-compare-price>
{% if current_variant.compare_at_price > current_variant.price %}
<span class="theme-money">{{ current_variant.compare_at_price | divided_by: unit | money }}</span>
{% endif %}
</span>
{% endif %}
{% render 'unit-price', variant: current_variant %} Per Pair
<span style="font-size:14px;"><br> MSRP: {{ product.metafields.msrp.msrp }}</span>
</div>

 

Replies 0 (0)