Back to posts

How to Create a Countdown Timer for Your Shopify Store: The Ultimate Tool to Drive Sales Right Now

Hamid Sabri / September 28, 2024

Adding a countdown timer to your Shopify store is one of the most effective ways to create urgency and drive sales. This guide shows you how to implement this powerful tool, step-by-step.

📘 Pro Tip: Always back up your theme before making changes. Use a duplicate theme to avoid any issues with your live store.


Table of Contents


Introduction

Creating a countdown timer isn't just about showing time ticking down—it's about driving action. When your Shopify store visitors see time slipping away, they’re more likely to make a purchase. This is urgency at its finest.

Why a Countdown Timer Works Like Magic on Shopify

  • Creates Urgency: The ticking clock tells visitors: “Act now, or miss out.”
  • Increases Conversions: A countdown timer triggers impulse purchases, reducing hesitation.
  • Perfect for Promotions: Whether it's a flash sale or seasonal offer, timers make offers feel special.

Step-by-Step Guide to Creating Your Shopify Countdown Timer

Step 1: Set Up Your HTML Structure

First, we need to create a place where our countdown timer will live. Add this to your announcement bar Liquid file (or wherever you want it to show up on your Shopify store).

  1. Go to your Shopify admin, then navigate to Online Store > Themes.
  2. Duplicate your theme before making any changes to ensure you have a backup.
  3. Click on the 3 dots next to your theme and select Edit code.
  4. In the search bar, search for announcement-bar.liquid.
  5. Once you're in the file, press Ctrl + F and search for the announcement-bar__message class to locate it.
  6. Replace that section with the following HTML code:
     
  <div id="countdown-timer" style="text-align: center;">
    <span style="font-weight: bold; font-size:30px; color:#f12052">HURRY UP!</span><br>
    <span>FALL SALE - <span style="color:#5ef98d">Ends in:</span> </span><br>
    <span id="countdown" style="font-weight: bold;"></span>
  </div>

Step 2: Set Up Custom CSS and JavaScript Files

To keep things organized, we’ll create separate custom files for the countdown timer's CSS and JavaScript. Follow these steps:

  1. Create Custom CSS File:

    • In your Shopify admin, go to Online Store > Themes.
    • Click the 3 dots and select Edit code.
    • Under the "Assets" folder, click on Add a new asset.
    • Create a new file named countdown-timer.css.

    Add the following CSS code:

       #countdown-timer {
      padding: 0;
      min-width: 50%;
      color: #fff;
      text-align: center;
      font-size: 14px;
      border-radius: 10px;
    }
    #countdown {
      display:flex;
      justify-content:center;
      gap:10px;
      font-weight: bold;
      font-size: 18px;
      
    }
     .label{
     font-size:12px  
         }
  2. Create Custom JavaScript File:

    • Under the "Assets" folder, click on Add a new asset.
    • Create a new file named countdown-timer.js.

    Add the following JavaScript code:

    // Set the end date and time for the countdown
    const saleEndDate = new Date("December 31, 2024 23:59:59").getTime();
    
    // Function to update the countdown every second
    function updateCountdown() {
      const now = new Date().getTime();
      const timeRemaining = saleEndDate - now;
    
      if (timeRemaining < 0) {
        document.getElementById("countdown-timer").innerHTML = "SALE ENDED!";
        clearInterval(countdownInterval);
        return;
      }
    
      const days = Math.floor(timeRemaining / (1000 * 60 * 60 * 24));
      const hours = Math.floor((timeRemaining % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
      const minutes = Math.floor((timeRemaining % (1000 * 60 * 60)) / (1000 * 60));
      const seconds = Math.floor((timeRemaining % (1000 * 60)) / 1000);
    
     document.getElementById("countdown").innerHTML = `
       <div class="countdown-item">${days}<div class="label">Days</div></div>
       <div class="countdown-item">${hours}<div class="label">Hrs</div></div>
       <div class="countdown-item">${minutes}<div class="label">Mins</div></div>
       <div class="countdown-item">${seconds}<div class="label">Secs</div></div>
     `;
     }
    
     // Update the countdown every second
     const countdownInterval = setInterval(updateCountdown, 1000);
     updateCountdown();
  3. Include the CSS and JavaScript Files in Your Liquid File:

    • Still in the code editor, search for announcement-bar.liquid.
    • Include links to your custom CSS and JS files by adding the following lines at the top of the liquid file:
    {{ 'countdown-timer.css' | asset_url | stylesheet_tag }}
    <script src="{{ 'countdown-timer.js' | asset_url }}" defer="defer"></script>

By doing this, your countdown timer will be fully functional, and you’ve kept your code organized and easy to maintain.

When to Use a Countdown Timer on Shopify

  • Flash Sales: Create urgency for limited-time offers.
  • Seasonal Promotions: Enhance engagement during holiday sales.
  • Product Launches: Drive hype and excitement.

Final Thoughts

You’ve got the tools to create a powerful countdown timer for your Shopify store. It’s time to add that urgency and turn visitors into buyers!