A space to discuss online store customization, theme development, and Liquid templating.
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
Hello,
I am trying to achieve the ability to have only one random product be available on the store at a time. This will be the same product for all users, so I can’t just run a script on the client side or it would randomize every time a user refreshed and would be different for all users.
Where could I write this secure code that would randomly select an active product every x hours? Seems fairly easy, but protecting it so the client couldn’t modify it is important.
Solved! Go to the solution
This is an accepted solution.
Hi @austint1012
I assuming your are familiar with the coding. To achieve this, I would create a for loop in all your products, then hide and show one product according to your random code.
Please don't forget to Like and Mark Solution to the post that helped you. Thanks!
This is an accepted solution.
Hi @austint1012
It seems like you do not really need randomization. Why dont you just set a product and change it whenever using Theme customization or Shopify Flow
This is an accepted solution.
Hi @austint1012
I assuming your are familiar with the coding. To achieve this, I would create a for loop in all your products, then hide and show one product according to your random code.
Please don't forget to Like and Mark Solution to the post that helped you. Thanks!
You can use the date for your random code, so the date would be the same for all user
Wouldn’t that still leave issues if someone were able to manipulate the browser/devices time zone?
Also, how would I keep track of it if I wanted to grab multiple random products in a day? There’s no way to keep them in sync across all clients.
It seems like the best route would be creating my own backend server that has an endpoint that returns the active product and the Shopify theme can hit that endpoint via a script. That seems like a lot of work, wondering if Shopify has something more out of the box.
Thanks again!
This is an accepted solution.
Hi @austint1012
It seems like you do not really need randomization. Why dont you just set a product and change it whenever using Theme customization or Shopify Flow
Hello,
That seems like a better solution. Where would I “set” the product as active though? Would that be in Shopify admin or via a custom script in my theme?