All guides › Product page sale countdown
Countdown timer on Dawn product pages for each product's sale (no app)
Disclosure: I build No-App Sections; this guide was written with AI assistance. The code on this page was written for this guide. It passes Shopify's Theme Check inside Dawn 16.0.0 and automated tests in headless Chrome, run against Dawn's own cart and variant events with mocked store data. It hasn't been run on a live store yet, so try it on a duplicate theme first.
Sitewide countdown bars count down to one date for the whole store. Product sales rarely work like that: the winter coat ends on Sunday, the boots ended yesterday, and the scarf was never on sale. This guide puts the end date on each product, as a metafield, and shows a timer on the product page only while that product's selected variant is actually reduced.
The rules the timer follows
- No end date on the product, or the date has passed: nothing renders.
- No variant has a compare-at price above its price: nothing renders. A timer next to a full price is fake urgency.
- Some variants are reduced and others aren't: the timer shows for the reduced ones and hides for the rest as the shopper switches.
- When the deadline passes on screen, the timer disappears. It never restarts and never shows a stuck 00:00:00.
Rule 4 matters beyond tidiness. Timers that reset for each visitor, or that count down to a deadline that isn't real, can break UK and EU consumer protection rules on misleading urgency. This timer only reads the date you set.
Step 1: create the "Sale ends" metafield
In Settings → Custom data → Products, click Add definition:
- Name: Sale ends
- Namespace and key:
custom.sale_ends - Type: Date and time (one value)
Save, then open a product that's on sale. Its Sale ends field is near the bottom of the product page in the admin. Pick the date and time the sale really ends.
Step 2: add the timer block
Customize your theme (on a duplicate first), open Products → Default product, and in Product information click Add block → Custom Liquid. Drag it under Price and paste:
{%- comment -%}
Product page sale countdown (Dawn "Custom Liquid" block in Product information).
Needs a product metafield definition: namespace and key custom.sale_ends, type "Date and time".
Shows only while the selected variant is actually reduced (compare-at price above price)
and the end date is in the future.
{%- endcomment -%}
{%- liquid
assign sale_ends = product.metafields.custom.sale_ends.value
assign any_reduced = false
for v in product.variants
if v.compare_at_price > v.price
assign any_reduced = true
break
endif
endfor
assign current = product.selected_or_first_available_variant
assign current_reduced = false
if current.compare_at_price > current.price
assign current_reduced = true
endif
assign ends_at = 0
if sale_ends != blank
assign ends_at = sale_ends | date: '%s' | plus: 0
endif
assign now_s = 'now' | date: '%s' | plus: 0
-%}
{%- if any_reduced and ends_at > now_s -%}
<div
class="pct"
id="pct-{{ section.id }}"
data-section="{{ section.id }}"
data-ends="{{ ends_at }}"
data-reduced="{{ current_reduced }}"
{% unless current_reduced %}
hidden
{% endunless %}
>
<p class="pct__line">
Sale price ends in <strong class="pct__left" role="timer">{{ sale_ends | date: '%-d %b %Y, %H:%M' }}</strong>
</p>
<p class="pct__date">Ends {{ sale_ends | date: '%A %-d %B %Y at %H:%M' }}</p>
</div>
<style>
.pct { margin: 0 0 1.5rem; }
.pct p { margin: 0; }
.pct__left { font-variant-numeric: tabular-nums; }
.pct__date { font-size: 1.2rem; opacity: 0.75; }
</style>
<script>
(function () {
var el = document.getElementById('pct-{{ section.id }}');
if (!el) return;
var endsMs = parseInt(el.dataset.ends, 10) * 1000;
var reduced = el.dataset.reduced === 'true';
var left = el.querySelector('.pct__left');
var timer;
function pad(n) { return (n < 10 ? '0' : '') + n; }
function tick() {
var ms = endsMs - Date.now();
if (ms <= 0) {
/* The deadline has passed: remove the timer rather than show 00:00:00 or restart it. */
clearInterval(timer);
el.remove();
return;
}
var s = Math.floor(ms / 1000);
var d = Math.floor(s / 86400);
left.textContent = (d ? d + 'd ' : '') + pad(Math.floor((s % 86400) / 3600)) + ':' + pad(Math.floor((s % 3600) / 60)) + ':' + pad(s % 60);
el.hidden = !reduced;
}
tick();
timer = setInterval(tick, 1000);
function init() {
if (typeof subscribe !== 'function' || typeof PUB_SUB_EVENTS === 'undefined') return;
subscribe(PUB_SUB_EVENTS.variantChange, function (event) {
if (!event.data || event.data.sectionId !== el.dataset.section) return;
var v = event.data.variant;
reduced = !!(v && v.compare_at_price && v.compare_at_price > v.price);
if (el.isConnected) el.hidden = !reduced;
});
}
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init);
else init();
})();
</script>
{%- endif -%}
What each part does
- The
forloop checks every variant, not just the first. That way the block exists on the page whenever any variant is on sale, and JavaScript can reveal it when the shopper picks one. date: '%s'turns the metafield and "now" into Unix seconds, so Liquid can compare them as numbers. The same number goes intodata-endsfor the browser, which means every shopper's timer is counting to the same moment.- The text inside the timer starts out as the end date, and the line under it reads "Ends Monday 30 November 2026 at 23:59". Shoppers without JavaScript still see a correct date, just not the ticking.
PUB_SUB_EVENTS.variantChangeis Dawn's variant event. Itsvarianthaspriceandcompare_at_price, which is all the block needs to decide whether to show.
Time zones
Shopify stores date-and-time metafields in ISO 8601. Liquid prints dates in your store's time zone (Settings → General). After you save the metafield, check the "Ends …" line the block prints under the timer. If it says the time you meant, the countdown is counting to it. Check this once for a date in summer time and once for a date in winter time if your sales span the clock change.
Other themes
The Liquid part works in any Online Store 2.0 theme with a Custom Liquid block. The variant switching listens to Dawn's pub/sub. In a theme without it, the timer still counts down, but it keeps the visibility of the variant that was selected on page load. In that case, use it on products where every variant has the same sale.
Testing checklist
- Product with no Sale ends date: no timer.
- Set a date two days ahead, with every variant reduced: a ticking "2d hh:mm:ss".
- Remove the compare-at price from one variant and select it: the timer hides. Select a reduced one again: it comes back.
- Set the date two minutes ahead and watch it pass: the timer disappears.
- Reload the page: the remaining time continues and doesn't reset.
One sale for the whole store? Use a bar instead
If your sale has a single end date across the store, the Announcement + countdown section shows it in an announcement bar on every page. You set the message, link, end date and colours in the theme editor, and choose whether it hides or says "Offer ended" when time's up. It's £12 one-off, for one store. It's tested on Dawn and Horizon. Other Online Store 2.0 themes may need small style tweaks. It's sitewide, not per product, so keep this block for product-level sales.
FAQ
Why a metafield instead of a block setting?
A block setting would give every product the same date, because all products share the Default product template. A metafield belongs to the product.
Can I show it on collection pages too?
The same metafield works in a product card, but Dawn's card snippet isn't a block, so you'd edit snippets/card-product.liquid. That's a bigger change and isn't covered here.
Does the sale price switch back automatically at the end?
No. The timer only displays the date. Shopify won't change your prices when it ends, so schedule the price change with your usual tools or remove the compare-at prices yourself.
What happens on a cached page after the sale ends?
The browser compares the end time with its own clock on every tick, so a stale page removes the timer as soon as it loads.
Is "Sale price ends in" required wording?
No, change it freely. Keep the end date visible, though: it's the honest part of the message.