Last active
March 10, 2021 12:35
-
-
Save Cam/c2e88ae136ec720238d42fe4a0183860 to your computer and use it in GitHub Desktop.
Shopify automatic discounts in cart without Plus sample code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script>if (typeof Shopify === "undefined") var Shopify = {}; Shopify.cart = {{ cart | json }};</script> | |
{% assign all_items_count = 0 %} | |
{% assign discount_line_total = 0 %} | |
{% if cart.item_count > 0 %} | |
{% for item in cart.items %} | |
{{ item.title }} | |
{{ item.price | money }} | |
{% if settings.discounts_enable %} | |
{% if item.variant.title contains '1L'%} | |
{% assign items_count = items_count | plus: item.quantity %} | |
{% assign discount_line_total = discount_line_total | plus: item.line_price %} | |
{% endif %} | |
{% endif %} | |
{% endfor %} | |
{% if settings.discounts_enable %} | |
{% if items_count >= 3 %} | |
{% assign discount = '1LBULK15' %} | |
{% assign discount_percent = 0.15 %} | |
{% endif %} | |
{% if items_count >= 6 %} | |
{% assign discount = '1LBULK20' %} | |
{% assign discount_percent = 0.20 %} | |
{% endif %} | |
{% if items_count >= 12 %} | |
{% assign discount = '1LBULK30' %} | |
{% assign discount_percent = 0.30 %} | |
{% endif %} | |
<script> | |
var discount = '{{ discount }}' | |
document.getElementById('cart_form').action = "/cart?discount=" + discount; | |
</script> | |
{% assign discount_amount = discount_line_total | times: discount_percent | floor %} | |
{% assign discount_amount_money = discount_amount | money %} | |
{% assign discounted_total = cart.total_price | minus: discount_amount | floor %} | |
{% endif %} | |
{% if settings.flash_discount_enable %} | |
<script> | |
var discount = '{{ settings.flash_discount }}' | |
document.getElementById('cart_form').action = "/cart?discount=" + discount; | |
</script> | |
{% endif %} | |
{% if settings.discounts_enable and discount_percent > 0 %} | |
{ 'cart.general.subtotal' | t }} | |
{{ discounted_total | money }} | |
{{ 'cart.general.savings_html' | t: price: discount_amount_money }} | |
{% else %} | |
{{ cart.total_price | money }} | |
{% endif %} | |
{% if cart.total_discounts > 0 %} | |
{% assign savings = cart.total_discounts | money %} | |
{{ 'cart.general.savings_html' | t: price: savings }} | |
</p> | |
{% endif %} | |
{% else %} | |
{% comment %} | |
The cart is empty | |
{% endcomment %} | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Cam what is this code used for? to have multiple automatic discount running?