Displaying expiry or best before dates on your storefront
Freshly can show each product's expiry or best-before date on your storefront. It saves the date to a Shopify metafield, and you display that metafield in your theme, either with the theme editor (no code) or by adding a Liquid snippet. This feature is available on paid Freshly plans.
Step 1: Turn on expiry date metafields in Freshly
- In Freshly, go to Preferences.
- In Expiry date on storefront, check Enable display of expiry dates on product pages.
- Click Save. Preferences aren't saved automatically.
Within a few minutes, Freshly saves dates to these metafields and keeps them updated as batches change:
| Metafield | Owner | What it contains |
|---|---|---|
freshly.expiry_date |
Product | The earliest expiry date among the product's in-stock, unexpired batches, across all variants and locations |
freshly.expiry_date |
Variant | The earliest expiry date among that variant's in-stock, unexpired batches |
Both are date metafields. If a product or variant has no in-stock batch with an expiry date, Freshly removes the metafield and nothing is shown.
Step 2: Show the date in your theme
Choose one option.
Option A: Theme editor (no code)
This works with themes that support dynamic sources (Online Store 2.0 themes).
First, give Shopify a definition for the Freshly metafield so the theme editor can find it:
- From your Shopify admin, go to Settings > Metafields and metaobjects.
- Click Products.
- Click View unstructured metafields (or View all > View unstructured metafields).
- Click Add definition next to
freshly.expiry_date. - Enter a name, such as "Expiry date".
- Click Select type and choose Date.
- Click Save, review the results, then click Save definition.
To show variant-level dates, repeat these steps under Variants.
Then add the date to your product page:
- From your Shopify admin, go to Online Store, find your theme, and click Edit theme.
- Open a product template.
- In the section that shows the product's title and price (often called "Product information"; names vary by theme), click Add block and choose a text block.
- In the block's text setting, type a label such as "Best before:", then click the Connect dynamic source icon and choose the Expiry date metafield.
- Drag the block to where you want it, for example, under the price, and click Save.
Option B: Liquid code
Use this if your theme doesn't support dynamic sources, or if you want full control over the date format.
If your theme has a custom Liquid block (names vary by theme), add one to the product information section in the theme editor and paste the code there. Otherwise, edit the theme code:
- Duplicate your theme as a backup. From your Shopify admin, go to Online Store, then use the menu icon (...) next to your theme.
- From the same menu, click Edit code.
- Open the section or snippet that renders your product page's price. File names vary by theme. Ask your theme developer if you're not sure.
- Paste one of the snippets below where you want the date to appear, then click Save.
Product-level date (earliest date across all variants):
{% assign expiry = product.metafields.freshly.expiry_date.value %}
{% if expiry != blank %}
<p>Expiry date: {{ expiry | date: "%Y/%m/%d" }}</p>
{% endif %}
Date for the selected variant:
{% assign expiry = product.selected_or_first_available_variant.metafields.freshly.expiry_date.value %}
{% if expiry != blank %}
<p>Expiry date: {{ expiry | date: "%Y/%m/%d" }}</p>
{% endif %}
You can change "Expiry date:" to any wording, such as "Best before:". To change the date format, edit "%Y/%m/%d" . For example, "%d/%m/%Y" shows 31/12/2026 and "%B %d, %Y" shows December 31, 2026.
Some themes update the price without reloading the page when a shopper picks a different variant. In those themes, the variant date may not change until the page reloads.
Troubleshooting
- No date shows. Check that the product has an in-stock batch with an expiry date in Freshly, that the setting is saved, and that you're on a paid plan. Then wait a few minutes and refresh the product page.
- The product shows the wrong variant's date. The product-level metafield always shows the earliest date across all variants. Use the variant snippet instead.
Need help with setup? Email us at hello@getfreshly.io.