{%- comment -%}
MIT License · (c) 2026 Lintel · https://lintelagency.com/resources/shopify-sections
{%- endcomment -%}
{%- comment -%}
Free shipping bar: "You're $23.00 away from free shipping" with a progress bar, worked out from
the cart total and the threshold you type. Liquid renders it from the cart on page load; a small
script reads /cart.js again whenever the theme changes the cart (add, change, update, clear), so
the message follows a cart drawer. Thresholds can be set per currency for Shopify Markets;
otherwise the store's threshold is converted at Shopify's rate. The section only displays: the
free shipping itself must be set up in Shopify (shipping rates or a free shipping discount).
Depends on: nothing
{%- endcomment -%}
{%- liquid
assign s = section.settings
assign currency = cart.currency.iso_code | default: shop.currency
assign threshold = s.threshold | times: 100 | round
assign exact = false
if currency == shop.currency
assign exact = true
endif
for block in section.blocks
assign code = block.settings.currency | strip | upcase
if code == currency and block.settings.amount > 0
assign threshold = block.settings.amount | times: 100 | round
assign exact = true
endif
endfor
assign total = cart.total_price | default: 0
assign remaining = threshold | minus: total
assign state = 'progress'
if cart.item_count == 0
assign state = 'empty'
elsif remaining <= 0
assign state = 'done'
assign remaining = 0
endif
assign percent = 0
if threshold > 0
assign percent = total | times: 100 | divided_by: threshold
endif
if percent > 100
assign percent = 100
endif
assign hide = false
if state == 'empty' and s.show_when_empty == false
assign hide = true
endif
if state == 'done' and s.hide_when_reached
assign hide = true
endif
# Another currency without its own threshold: the script converts at Shopify's rate first.
if exact == false
assign hide = true
endif
if request.design_mode
assign hide = false
endif
assign message = s.message_progress
if state == 'empty'
assign message = s.message_empty
elsif state == 'done'
assign message = s.message_success
endif
assign remaining_money = remaining | money
assign threshold_money = threshold | money
assign remaining_html = '' | append: remaining_money | append: ''
assign threshold_html = '' | append: threshold_money | append: ''
assign message = message | escape | replace: '{remaining}', remaining_html | replace: '{threshold}', threshold_html
-%}