Changing unit values based on Variant Options

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 %}

{{ current_variant.price | divided_by: unit| money }}

{% if product.compare_at_price_max > product.price %}
{{ ‘products.product.regular_price’ | t }}

{% if current_variant.compare_at_price > current_variant.price %}
{{ current_variant.compare_at_price | divided_by: unit | money }}
{% endif %}

{% endif %}
{% render ‘unit-price’, variant: current_variant %} Per Pair

MSRP: {{ product.metafields.msrp.msrp }}