Custom liquid not working as expected for conditional message in shopping cart

Solved

Custom liquid not working as expected for conditional message in shopping cart

alexandersparke
Shopify Partner
2 1 1

Hi guys,

 

I am using a theme which I have confirmed, supports the use of custom liquid sections. I am trying to run the code:

 

 

 

{% if cart.items_subtotal_price <= 7.98 %}
  {% if cart.item_count == 3 %}
    Add one more Single Reference Card to get £3.97 off!
  {% elsif cart.item_count == 2 %}
    Add two more Single Reference Cards to get £3.97 off!
  {% elsif cart.item_count == 1 %}
    Add three more Single Reference Cards to get £3.97 off!
  {% endif %}
{% endif %}

 

 

 

But when I try to test it, it doesn't work as expected. I am trying to use the code to capture the amount of items in cart and total price and announce that if they add x more items (to make total of 4 items) to the cart then they get a discount. 

 

Anyone able to spot any errors and suggest a quick fix?

 

I am new to Liquid so if it is a rookie error then I apologise

Accepted Solution (1)

alexandersparke
Shopify Partner
2 1 1

This is an accepted solution.

I found that the error was that I hadn't used the right format for price and I hadn't classified the "add  xxx" as a text box so it now works with code:

{% if cart.items_subtotal_price < 799 %}
  {% if cart.item_count == 3 %}
    <p style="text-align: center;">Add one more Single Reference Card to get £3.97 off!</p>
  {% elsif cart.item_count == 2 %}
    <p style="text-align: center;">Add two more Single Reference Cards to get £3.97 off!</p>
  {% elsif cart.item_count == 1 %}
    <p style="text-align: center;">Add three more Single Reference Cards to get £3.97 off!</p>
  {% elsif cart.item_count == 0 %}
    <p style="text-align: center;">Have you seen our Single Reference Card Collection?</p>
  {% endif %}
{% endif %}

 

Thanks if you spared a look!

View solution in original post

Replies 2 (2)

alexandersparke
Shopify Partner
2 1 1

This is an accepted solution.

I found that the error was that I hadn't used the right format for price and I hadn't classified the "add  xxx" as a text box so it now works with code:

{% if cart.items_subtotal_price < 799 %}
  {% if cart.item_count == 3 %}
    <p style="text-align: center;">Add one more Single Reference Card to get £3.97 off!</p>
  {% elsif cart.item_count == 2 %}
    <p style="text-align: center;">Add two more Single Reference Cards to get £3.97 off!</p>
  {% elsif cart.item_count == 1 %}
    <p style="text-align: center;">Add three more Single Reference Cards to get £3.97 off!</p>
  {% elsif cart.item_count == 0 %}
    <p style="text-align: center;">Have you seen our Single Reference Card Collection?</p>
  {% endif %}
{% endif %}

 

Thanks if you spared a look!

PaulNewton
Shopify Partner
6756 610 1437

Good work,

I found that the error was that I hadn't used the right format for price


To clarify for others the gotcha is prices, aka |money ,  are represented as cents , pennies ,  in shopify-liquid in themes.

https://shopify.dev/docs/api/liquid/objects/money#money-referencing-money-objects-directly 

Contact paull.newton+shopifyforum@gmail.com for the solutions you need


Save time & money ,Ask Questions The Smart Way


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Thank Paul with a Coffee for more answers or donate to eff.org