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.
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!
Hello,
Yes I am familiar with HTML, CSS, JS, and a little familiar with Liquid.
If I were to do that in a script on the theme for example, it would be a
different random product for every user - correct? Or is there another
place I can put that code to sync for all users?
@Made4uo-Ribe
Hello and thanks for the answer!
Yes I am familiar with HTML, CSS, JS, and a little familiar with Liquid.
However, if I were to do the randomizing in a script on the theme for example, it would be a different random product for every user - correct?
Or is there another place I can put that code to sync for all users? Preferably I would also like to talk to the client to also have a countdown to when the next random product will be selected.
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!
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?