Shipping cost if price under 400

henryenders
New Member
2 0 0

Hello,

I want to implement a shipping cost to the cart, if the price is lower than 400€. This is my code but it doesn't work well.

 {%-if cart.total_price >= 400 %}
              <p class="cart__taxes">Versandkosten: 4.99€</p>
{%- endif -%}

What did I wrong?

 

Greeting, Henry 

0 Likes
peterloane
Excursionist
31 4 11

This if statement is true (applies) if the cost is above (you are using >=) 400€ 

Is that what you intended?

Try <= for cost lower than 400€

 

Regards

Peter

Niki_S
Explorer
57 4 12

Hi henryenders,

as mentioned above, if you the shipping costs apply for orders under 400$, you have to use the opposite sign <= (saying equal to or lower than $400).

Plus, when using {%- -%} (with the hyphen) - you should use the same syntax on both sides, in your code, it's missing in the first row and the end.  

You can also add the { % else % } part of the if statement and inform the customer that the shipping cost is (I suppose) free . 

 {%- if cart.total_price <= 400 -%}
              <p class="cart__taxes">Versandkosten: 4.99€</p>
{%- else -%}
               <p class="your__class">Kostenfreie Lieferung</p>
{%- endif -%}

 

 

henryenders
New Member
2 0 0

Ok thank you! It Works when I go to the shipping cart but when I update the cart (because I want to buy 2 boards) then the script doesnt work any (doesnt update)

 

Video of it here:

https://www.loom.com/share/ae8813a140664be390282b223ac965b9

0 Likes
Niki_S
Explorer
57 4 12

Hi henryenders,

I just looked at it once again.

There are two things:

1. You need to add two more zeros in the price - I mean in the code (it's because of the cents). 

{%- if cart.total_price <= 40000 -%}
   <p class="cart__taxes">Versandkosten: 4.99€</p>
{%- else -%}
   <p class="your__class">Kostenfreie Lieferung</p>
{%- endif -%}

 

2. If you render the cart.total_price, it doesn't update unless you refresh the page. And therefore if your order is less then 400 EUR and then you add additional product and the price is above 400 EUR, the total price won't update. You would need to implement event listener and probably add JavaScript - but this is out of my knowledge, so I think anyone else would have to help.