All guides › Sale that ends itself

A limited-time sale that ends itself: automatic discount price and countdown on the product page

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.

The usual way to run a timed sale on Shopify is to lower prices and set compare-at prices. Then someone has to put them back at midnight. An automatic discount with an end date takes itself off, but Shopify doesn't show it on the product page: shoppers see the full price until the cart. This guide closes that gap. The product page shows the discounted price and a countdown for the same window as the discount, and both disappear at the end time, without a reload and without anyone touching a price.

How this differs from the compare-at countdown

The product page countdown guide times a sale you've already put on with compare-at prices. It counts down, but the prices stay low until you change them. Here the discount does the work and the page only describes it:

Compare-at countdownThis guide
Where the discount livesThe product priceAn automatic discount
At the end timeTimer stops; prices stay discounted until editedDiscount stops at checkout; the block hides itself
Collection pagesShow the sale priceShow the full price (see the limits)
Best forLong or per-product salesShort, hard-deadline sales (Black Friday, 48-hour drops)

What shoppers see

  • Before the start time: nothing. The block is in the page but hidden, and appears on its own at the start time if the page is open.
  • During the sale: £25.00 £20.00 with 20% off, applied in your cart, and "Sale ends Tue 1 Dec, 00:00 (your time): 2d 04:12:09" for a sale ending at midnight UK time on 30 November.
  • At the end time: the block removes itself. Checkout stops discounting at the same moment, because that's when the discount ends.
  • Products outside the sale collection, or sold-out variants: nothing.

The end time is shown in the shopper's own time zone, labelled "(your time)", so nobody in Dublin or Toronto has to convert from UTC.

The block

{%- comment -%}
  Shows a scheduled automatic discount on the product page, counts down to its end,
  and switches itself off at the end time without a page reload.
  Add as a "Custom Liquid" block directly under Price in Product information (Dawn 16).
  First create the discount in Shopify admin: Discounts > Amount off products > Automatic discount,
  Percentage, applies to the collection below, no minimum requirement, with a start AND an end date.
  Then copy the SAME percentage, collection and times (in UTC) here. Checkout is always the authority.
{%- endcomment -%}
{%- liquid
  assign sale_percent = 20
  assign sale_collection = 'black-friday'
  assign sale_starts = '2026-11-27T00:00:00Z'
  assign sale_ends = '2026-12-01T00:00:00Z'

  assign in_sale = false
  for c in product.collections
    if c.handle == sale_collection
      assign in_sale = true
      break
    endif
  endfor
  assign v = product.selected_or_first_available_variant
  assign now_s = 'now' | date: '%s' | plus: 0
  assign starts_s = sale_starts | date: '%s' | plus: 0
  assign ends_s = sale_ends | date: '%s' | plus: 0
  assign saving = v.price | times: sale_percent | divided_by: 100.0 | round
  assign sale_price = v.price | minus: saving
-%}
<div id="AutoSale-{{ section.id }}">
  {%- if in_sale and ends_s > now_s and v.available -%}
    <auto-sale
      class="auto-sale"
      data-section="{{ section.id }}"
      data-starts="{{ starts_s }}"
      data-ends="{{ ends_s }}"
      {% if starts_s > now_s %}
        hidden
      {% endif %}
    >
      <p class="auto-sale__prices">
        <s>{{ v.price | money }}</s>
        <strong>{{ sale_price | money }}</strong>
        <span>with {{ sale_percent }}% off, applied in your cart</span>
      </p>
      <p class="auto-sale__ends">
        Sale ends {{ sale_ends | date: '%-d %B %Y' }}<span class="auto-sale__left"></span>
      </p>
    </auto-sale>
  {%- endif -%}
</div>
<style>
  .auto-sale p { margin: 0.3rem 0; }
  .auto-sale__prices strong { font-size: 1.15em; }
  .auto-sale__ends { font-size: 0.9em; }
</style>
<script>
  if (!customElements.get('auto-sale')) {
    customElements.define('auto-sale', class extends HTMLElement {
      connectedCallback() {
        const ends = new Date(+this.dataset.ends * 1000);
        const local = new Intl.DateTimeFormat(document.documentElement.lang || undefined, { weekday: 'short', day: 'numeric', month: 'short', hour: '2-digit', minute: '2-digit' }).format(ends);
        this.querySelector('.auto-sale__ends').firstChild.textContent = 'Sale ends ' + local + ' (your time): ';
        this.tick();
        this.timer = setInterval(() => this.tick(), 1000);
      }
      disconnectedCallback() {
        clearInterval(this.timer);
      }
      tick() {
        const now = Date.now() / 1000;
        if (now >= +this.dataset.ends) {
          /* The automatic discount has ended at checkout too: drop the sale price, Dawn's normal price remains. */
          clearInterval(this.timer);
          this.remove();
          return;
        }
        this.hidden = now < +this.dataset.starts;
        const s = Math.floor(+this.dataset.ends - now);
        const pad = (n) => String(n).padStart(2, '0');
        const days = Math.floor(s / 86400);
        this.querySelector('.auto-sale__left').textContent =
          (days ? days + 'd ' : '') + pad(Math.floor((s % 86400) / 3600)) + ':' + pad(Math.floor((s % 3600) / 60)) + ':' + pad(s % 60);
      }
    });
  }
  (function () {
    var id = {{ section.id | json }};
    /* Dawn re-renders the section for each variant: copy this block from that HTML, or empty it. */
    function listen() {
      if (typeof subscribe !== 'function' || typeof PUB_SUB_EVENTS === 'undefined') return;
      var store = (window.autoSaleOff = window.autoSaleOff || {});
      if (store[id]) store[id]();
      store[id] = subscribe(PUB_SUB_EVENTS.variantChange, function (event) {
        if (event.data.sectionId !== id || !event.data.html) return;
        var box = document.getElementById('AutoSale-' + id);
        var fresh = event.data.html.getElementById('AutoSale-' + id);
        if (box) box.innerHTML = fresh ? fresh.innerHTML : '';
      });
    }
    if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', listen);
    else listen();
  })();
</script>

Install it

  1. Create the automatic discount. In Discounts → Create discount → Amount off products, choose Automatic discount, give it a title (shown in the cart), set Percentage, apply it to your sale collection, choose No minimum requirements, and set a start date and an end date. Save.
  2. Open the product template. Go to Online Store → Themes → Customize → Products → Default product.
  3. Add a Custom Liquid block under Price. In Product information, add a Custom Liquid block and drag it directly under Price.
  4. Paste and copy your settings across. Paste the block and set sale_percent, sale_collection, sale_starts and sale_ends to the same values as the discount, with times in UTC.
  5. Test with a short window. Set the end a few minutes ahead, open a sale product, and watch the block disappear. Then add the product to the cart before the end and check the cart shows the same price.

Keep the discount and the block in step

This is the part to get right. The block can't read your discount settings, so you're setting the same sale up twice:

  • Percentage: sale_percent must match the discount value.
  • Products: the discount must apply to the collection in sale_collection (use its handle, from the collection's URL), and to nothing else.
  • Times: Shopify shows discount times in your store's time zone. The block wants UTC with a Z. In November the UK is on GMT, so they're the same. In summer, 1am BST is 00:00:00Z. You can also write an offset, like 2026-07-01T00:00:00+01:00.
  • No minimum: use "No minimum requirements". With a minimum spend or quantity, "applied in your cart" isn't true for a single item.

Checkout is always the authority. If the block and the discount disagree, the customer pays what checkout says.

Limits

  • Collection pages and search still show full prices. Changing those means editing Dawn's card-product snippet the same way. Most shops add a "20% off in your cart" announcement bar instead.
  • Rounding: the block rounds the saving to the penny per item. Shopify rounds discounts per line, so on rare prices the total can differ by a penny.
  • Other discounts: if a code or another automatic discount can combine with this one, the page can't show that. Turn combinations off for the sale, or word it as "from 20% off".
  • Cached pages: Shopify can serve a page rendered a little earlier. The JavaScript checks the clock every second, so a cached page still hides the block at the end time.

Want the countdown in the announcement bar, on every page?

The Countdown bar is a sitewide announcement bar with a countdown to one end time, which it can hide automatically when the time is up. It doesn't know about your discount and doesn't show discounted prices: it's the "sale ends in…" message at the top of every page, collection pages included. Pair it with the block above if you want both. £12 one-off, for one store.

Buy the countdown bar, £12 Try the live demo

FAQ

Why doesn't Shopify show automatic discounts on the product page?

Automatic discounts are worked out in the cart and at checkout, against the whole order. The product page shows the product's own price. Themes would have to guess, which is why this block uses settings you copy across.

Can Shopify Flow change prices back at the end of a sale?

Flow doesn't have a price-change action, as far as I know. Shopify's Launchpad app can schedule price changes, but it's for Shopify Plus. An automatic discount with an end date is the no-app way to make a sale end by itself.

Can I use a fixed amount instead of a percentage?

Yes, with a small change: replace the saving line with assign saving = 500 for £5 off (amounts are in pence), and change the "with … off" wording to "with £5 off". In the discount, leave "Only apply discount once per order" unticked, so £5 comes off each item.

What if the shopper's computer clock is wrong?

The countdown uses the device clock, so it can be out by that much. Checkout uses Shopify's clock, so the price at checkout is still right.

Does it work in multiple currencies?

The block formats prices with money, so it shows the current currency. The percentage is the same in every currency, so the saving is correct.