How to change product labels from 'New' to 'OnSale'?

I want to change label on the product from (New) to (onSale) If the product is available for a month or more

Hi @Abanoub_Talaat

Welcome to Shopify Community.

Aibek is here from Speedimize.io agency.

As a solution, you can use the code below:

{% comment %} Product created date by seconds {% endcomment %}
{% assign productCreatedAt = product.created_at | date: '%s' %}

{% comment %} Current date by seconds {% endcomment %}
{% assign today = 'now' | date: '%s' %}
 
{% comment %} Difference in seconds {% endcomment %}
{% assign diffSeconds = today | minus: productCreatedAt %}
 
{% comment %} Difference in days {% endcomment %}
{% assign diffDays = diffSeconds | divided_by: 3600 | divided_by: 24 %}

{% comment %} Let's say more than month {% endcomment %}
{% if diffDays > 30 %} 
onSale
{% else %}
New
{% endif %}

Hope that helps you.

Best Regards,

Aibek

1 Like