I’m trying to code a dynamic custom free shipping bar for the impulse theme.
I managed to add the text in the cart drawer by following this steps.
-
Create a snippet called dynamic-free-shipping-bar.liquid
-
Add this code into it
<div id="free-shipping-bar">
{% if cart.total_price >= 10000 %}
<p>You qualify for free shipping!</p>
{% else %}
<p class="freeBar">Spend {{ 10000 | minus: cart.total_price | money }} more to qualify for free shipping!</p>
{% endif %}
</div>
<script>
function updateFreeShippingBar() {
const freeShippingBar = document.getElementById('free-shipping-bar');
const cartTotal = {{ cart.total_price | money_without_currency }};
const threshold = 10000;
if (cartTotal >= threshold) {
freeShippingBar.innerHTML = '<p style="color:blue;">You qualify for free shipping on orders over $100!</p>';
} else {
freeShippingBar.innerHTML = `<p style="color:blue;">Spend $${threshold - cartTotal} more to qualify for free shipping!</p>`;
}
}
document.addEventListener('DOMContentLoaded', function () {
updateFreeShippingBar();
});
// Use Shopify's AJAX Cart API to listen for cart updates
document.addEventListener('cart:updated', updateFreeShippingBar);
</script>
- Add this line of code
{% include 'dynamic-free-shipping-bar' %}
in the cart.ajax.liquid file.
It is showing right now as the picture below
But when I try to customize it I can’t.
I added this CSS at the bottom of the theme.css.liquid file
#free-shipping-bar {
background-color: #000000;
color: white;
text-align: center;
}
but it isn’t working.
What do I need to do to be able to customize the free shipping bar?
Help would be appreciated.

