Displaying expiry or best before dates on your storefront

To display the expiry or best before dates for your products or variants on your storefront, enable the "Enable display of expiry dates on product pages" setting on the preferences page. This option will update the metafields on the product and variant on your store every 10 minutes.

Once you have enabled the Expiry date on the storefront, please make sure to hit the save button either from the top right or right bottom as these settings are not auto-saved. Freshly gives you the option to add the liquid code on your storefront for either the product or variant to show the expiry dates for your customers:

Note: Please ensure that your products already have the batches assigned. For unassigned batches, no date will be displayed.

1.    In order to access the liquid code for your Shopify store, from the left under Sales Channels, please click Online Store> Themes> Actions> Edit Code

2.    Search for “product.liquid” in the search bar and access the “main-product.liquid” code. Please note if you have a custom theme, the name for this will differ. You just need to make sure to access the main product code.

3.    Search for the render price code by using ctrl/cmd+F on your keyboard and typing “price”. It usually exists around line 189 of the code as shown in the below screenshot:

4.    Paste the Freshly liquid code beneath the price render as we are going to display the expiry date right beneath the pricing for the product.

{% unless product.metafields.freshly.expiry_date == blank %}
  <strong> Expiry date: {{ product.metafields.freshly.expiry_date | date: "%Y/%m/%d" }} </strong>
{% endunless %}

The “Expiry Date” wording can be changed to anything of your choice such as “Best Before”. The date formatting can also be changed by altering ("%Y/%m/%d" ) You can move month and year around and completely remove the date if needed etc. 

5.    Once changes are made, hit the save button, visit the product page on your Shopify store, hit refresh and you will find the expiry date displayed beneath the pricing as shown below screenshot:

6.    To display the expiry date per variant, please use the below code:

{% unless variant.metafields.freshly.expiry_date == blank %}
  <strong> Expiry date: {{ variant.metafields.freshly.expiry_date | date: "%Y/%m/%d" }} </strong>
{% endunless %}

Note: Please make sure to wrap this code where the variant variable is accessible.

If you need assistance with setup, feel free to reach out to us at hello@getfreshly.io

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us