Generate random product

{% assign min = 1 %}
{% assign max = 9 %}
{% assign diff = max | minus: min %}
{% assign randomNumber = "now" | date: "%N" | modulo: diff | plus: min %}

  {% for product1 in collections.all.products %}
		{% if forloop.index == randomNumber %}
     		{%- assign product = product1 -%}
		{% endif %}
  {% endfor %}

Leave a Reply

Your email address will not be published. Required fields are marked *