Ad

Detect Whether A Product Is New. Shopify Liquid

- 1 answer

I want to be able to display the text 'New' alongside a product that was added recently in shopify.

Something like {% if product.date_added > ten_days_ago %}New{% endif %}

EDIT

Seems like there is some undocumented objects of product which I found out by console logging {{ product | json }}.

{{ product.created_at }}
{{ product.published_at }}
Ad

Answer

You can do something like this.

{% assign product_date = product.published_at | date: "%s" %}
{% assign current_date = 'now' | date: '%s' %}
{% assign difference = current_date | minus: product_date | date: "%d" %}

{% if difference < 10 %}
    New
{% endif %}
Ad
source: stackoverflow.com
Ad