This article will demonstrate how to list best selling products on homepage dynamically. Most of the ecommerce site has this requirement to present the most sold products on homepage as to showcase the shopping trend. The shopify inbuilt feature is enough to do this, and below are the steps explained.
-
Create a collection named Best selling
- Condition : Product price is greater than $0. With this you will include all products on this custom collection.
- Sort collection by Best selling. Among all the products which we included with the condition above, now we are sorting by best selling on the collection.
2. Fetch the collection
Now when we fetch this collection anywhere either in homepage or anywhere we obtain the products sorted with best selling. And that is the best selling list of products.
3. On homepage
3.1 via section. – Add a section which would allow you to list from a collection and choose the “Best selling” collection.
3.2 via liquid template
{% if collections.best_selling.products.size > 0 %}
{% for product in collections.best_selling.products %}
<li>
<img src="{{ product.featured_image | product_img_url: 'medium' }}" alt="{{ product.title | escape }}" />
<a class="shop-now" href="{{ product.url }}">{{ product.title | escape }}</a>
</li>
{% endfor %}
{% endif %}










Leave a Reply