Retrieve a number of randomly-chosen products in Shopify

Sell Online With Shopify
Trusted by millions of businesses worldwide
Sign up for a free trial and enjoy 3 months of Shopify for $1/month on select plans.

I need a solution for retrieving a number of randomly-chosen products on my homepage (or any pages). I read in here: Featuring a number of randomly-chosen products on your homepage. But I think It’s not good for me. I continue reading an article here: Featuring one randomly-chosen product on your homepage. I think it’s a good solution. Really this solution supports retrieving only a product, but I can get more if I change the variant for “limit”. Good…. But after that I found an issue with it.

Example: That collection has 10 products and I want to retrieve 5 products. All are OK if the index number is 1 or 2 or 3 or 4 or 5 but if the index number is greater than 5 We will miss some products.

I’m thinking… and after I have solved this issue. Sharing with everybody.

Get index number:

Count product missing

Now we can show products

If the current index doesn’t take up enough of the products. We need add below code:

Looking for Shopify Experts?

Hura Apps can help you take your store to the next level

Our team of experienced designers and developers can help you create a beautiful, high-converting Shopify store that will drive sales and increase customer satisfaction. From custom design to app development and optimization, we have the skills and expertise to help you achieve your eCommerce goals.

Get in touch

You may also like...

Leave a Reply

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