Have your say in Community Polls: What was/is your greatest motivation to start your own business?

How to add a daily reset countdown to the announcement bar?

How to add a daily reset countdown to the announcement bar?

Quincko
Tourist
17 0 1

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

Replies 2 (2)

PageFly-Victor
Shopify Partner
7865 1786 3117

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>

 

PageFlyVictor_0-1674004576100.jpeg

 

Hope this can help you solve the issue 

 

Best regards,

Victor | PageFly

faecom1
Excursionist
31 0 4

 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?