Hi guys,
I am facing an issue on checkout page. Here's what is happening. I have a store on which we are offering some samples if a customer orders above certain amount. So, if a customer reaches say $75, we offer free samples worth $10. I have updated cart.liquid to get this working and it works fine. It subtracts the cost of samples from total and then displays the total. But when I click checkout button the discount does not show up on checkout page. Total amount is not deducted.
Please refer to these screenshots:
subtotal is $116-10 = $106
Total displays $116
You can see the subtotal is $106 in first screenshot(cart page) but in second screenshot(checkout page) it shows $116.
This is the code which I have added on cart page.
<div class="cart-subtotal">
{% assign newTotal = cart.total_price %}
{% assign SampleDis = 0.0 %}
{% assign TotalWithoutSample = 0.0 %}
{% for item in cart.items %}
{% if item.product.tags contains 'sample' %}
{% assign blockdisplay = block %}
{% assign SampleDis = SampleDis | plus: item.line_price %}
{% else %}
{% assign blockdisplay = none %}
{% assign TotalWithoutSample = TotalWithoutSample | plus: item.line_price %}
{% endif %}
{% endfor %}
{% if TotalWithoutSample >= 7500 %}
{% if SampleDis < 1000.0 %}
{% assign newTotal = newTotal | minus:SampleDis %}
{% else %}
{% assign SampleDis = 1000 %}
{% assign newTotal = newTotal | minus:SampleDis %}
{% endif %}
<span class="cart-subtotal__title" style="display:{{blockdisplay}}">Sample Discount</span>
<span class="cart-subtotal__price" style="display:{{blockdisplay}}">-{{SampleDis | money}}</span>
{% endif %}
</div>
<div class="cart-subtotal">
<span class="cart-subtotal__title">{{ 'cart.general.subtotal' | t }}</span>
<span class="cart-subtotal__price" data-cart-subtotal>{{ newTotal | money_with_currency }}</span>
</div>
Any help would be appreciated.
Thank You
Hello,
It seems that you are trying to modify the actual cart price using only Liquid templating, and that's not possible. You can do it using Shopify in-built automatic discounts.
https://help.shopify.com/en/manual/discounts/automatic-discounts
Cheers!
User | Count |
---|---|
25 | |
24 | |
22 | |
19 | |
13 |