Hey folks! I hope everyone is safe and well.
I’m attempting to implement a line of code which will either multiply a price by 1.2 depending on a customer tag.
Long story short, if a customer is tagged with “WHOLESALE”, I wish to show the price as is.
If the customer is not tagged “WHOLESALE”, then I want to multiply the price by 1.2.
I’ve managed to get it to work, however it will return several prices, with x1 and x1.2 in sequence (see screenshot).
The code I am using right now is shown below also.
Can somebody assist please?
{{ 'product.general.regular_price' | t }}
{{- product.selected_or_first_available_variant.compare_at_price | times: 1.2 | money -}}
{%- else -%}
{% for tag in customer.tags %}
{{ 'product.general.sale_price' | t }}
{% if product.price == 0%}£TBC
{%- else -%}
{% if tag == "WHOLESALE" %}
{{- product.selected_or_first_available_variant.price | times: 1 | money -}}
{%- else -%}
{{- product.selected_or_first_available_variant.price | times: 1.2 | money -}}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
@UK_Aspire_Vendo - this line is correct {% for tag in customer.tags %} but due to it condition is checked for each tag and it is true for each tag, so prices are posted like that, If I am not wrong then this particular product has 7 tags, please check
1 Like
@UK_Aspire_Vendo - PLease take backup of your code and then replace it by this code below
{% assign flag=false %}
{{ 'product.general.regular_price' | t }}
{{- product.selected_or_first_available_variant.compare_at_price | times: 1.2 | money -}}
{%- else -%}
{% for tag in customer.tags %}
{{ 'product.general.sale_price' | t }}
{% if product.price == 0%}£TBC
{%- else -%}
{% if tag == "WHOLESALE" %}
{% assign flag=true %}
{%- else -%}
{{- product.selected_or_first_available_variant.price | times: 1.2 | money -}}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{% if flag=="true" %}
{{- product.selected_or_first_available_variant.price | times: 1 | money -}}
{%- endif - %}
{%- endif -%}
1 Like
Unfortunately this did not work - I logged in with my test account (which has the WHOLESALE tag) and not only did it not show the x1 price, it showed 5x the x1.2 price.
Appreciate the help!
I think I’ve found a solution, it may be a bit hacky so I’d appreciate your advice on this.
Basically our store operates on whether a customer is tagged “WHOLESALE” or “RETAIL”
I duplicated the code, and replaced “WHOLESALE” with “RETAIL” and adjusted the multiplier variation to suit, this does seem to work, but obviously it leaves us open to customers either being tagged with neither tag or both, but I’m prepared to take that hit. Do you think the code below will suffice?
{{ 'product.general.sale_price' | t }}
{% if product.price == 0%}£TBC
{%- else -%}
{% for tag in customer.tags %}
{% if tag == "WHOLESALE" %}
{{- product.selected_or_first_available_variant.price | times: 1 | money -}}
{%- endif -%}
{%- else -%}
{{- product.selected_or_first_available_variant.price | times: 1.2 | money -}}
{%- endfor -%}
{%- endif -%}
{%- endif -%}
{{ 'product.general.sale_price' | t }}
{% if product.price == 0%}£TBC
{%- else -%}
{% for tag in customer.tags %}
{% if tag == "RETAIL" %}
{{- product.selected_or_first_available_variant.price | times: 1.2 | money -}}
{%- endif -%}
{%- else -%}
{{- product.selected_or_first_available_variant.price | times: 1 | money -}}
{%- endfor -%}
{%- endif -%}
@UK_Aspire_Vendo - has this stopped price from showing multiple times?
I have figured out this code for myself - as seen below.
There are variations on the code depending on the page, however it is largely the same.
{% if customer %}
{% if product.price == 0%}£TBC
{%- else -%}
{% for tag in customer.tags %}
{% if tag == "WHOLESALE" %}
{{- product.price | times: 1 | money -}} +VAT.
{%- endif -%}
{%- endfor -%}
{% for tag in customer.tags %}
{% if tag == "RETAIL" %}
{% if product.price == 0%}£TBC
{%- else -%}
{{- product.price | times: 1.2 | money -}} INC. VAT.
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- endif -%}
{%- endif -%}
{% if customer %}
{%- else -%}
{% if product.price == 0%}£TBC
{%- else -%}
{{- product.price | times: 1.2 | money -}} INC. VAT.
{%- endif -%}
{%- endif -%}