Shopify themes, liquid, logos, and UX
Hi,
can someone tell me how to add a countdown to the announcement bar? I would need the Countdown to automatically reset every day.
Thanks and best regards
Hi @Quincko
This is Victor from PageFly - Shopify Page Builder App
Please follow this guide to add the timer to your announcement bar
Online store > themes > Actions > Edit code > Snippets > ➕ Create a new snippet name :
flash-sale-script.liquid
Paste code and save:
<script>
/*
Javascript count down timer
data format: 2021-10-7 18:00:00
*/
(function () {
function convertDateForIos(date) {
var arr = date.split(/[- :]/);
date = new Date(arr[0], arr[1]-1, arr[2], arr[3], arr[4], arr[5]).getTime();
return date;
}
const second = 1000,
minute = second * 60,
hour = minute * 60,
day = hour * 24;
// get all timer placeholder by class
const timers = document.querySelectorAll('.CountdownTimer');
let endDay = "2022-08-29 18:00:00",
countDown = convertDateForIos(endDay);
let x = '';
let timerHtml = '';
x = setInterval(function ins1() {
// lock time zone
let c = new Date().toLocaleString('en-US', { timeZone: 'Europe/London' });
let sensibleFormat = new Date(c);
let now = sensibleFormat.getTime(),
distance = countDown - now;
let dayText = Math.floor(distance / (day));
let hoursText = Math.floor((distance % (day)) / (hour));
let minutesText = Math.floor((distance % (hour)) / (minute));
let secondText = Math.floor((distance % (minute)) / second);
if(dayText){
timerHtml = '<b>'+dayText+'</b>d <b>'+hoursText+'</b>h <b>'+minutesText+'</b>m <b>'+secondText.toString().padStart(2, '0')+'</b>s';
}else{
timerHtml = '<b>'+hoursText+'h '+minutesText+'m '+secondText+'s</b>';
}
timers.forEach(function(element){
element.innerHTML = timerHtml;
});
//do something later when date is reached
if (distance < 0) {
clearInterval(x);
}
return ins1;
//seconds
}(), 1000);
}());
</script>
Then go to theme.liquid
Paste code before </body>
{% include 'flash-sale-script' %}
Now you have the timer, and this is to use it in announcement bar
Online store > themes > Actions > Edit code > Sections > announcement-bar
Paste the code at the position you want (the timer is right after the announcement bar text)
<span class="CountdownTimer"></span>
Hope this can help you solve the issue
Best regards,
Victor | PageFly
Hi i'm trying to use this code. But i can't seen to get it to work using Dawn theme.
Could you try it with a fresh dawn theme and share Any ideas on what I can try changing to fix?
In Canada, payment processors, like those that provide payment processing services t...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025