How to make Dynamic Button

Hi Experts. I wanted to know if it is possible to make a button that can change its link Dynamically.

I want to add a Button to the Product Page which will change its link Depending on what product the user opens. Like if you open Coffee the button should take you to the coffe page if tea then it changes links and takes you to tea.

is it possible? please help

You can set the Button’s link property .

Thank you, but I can’t find the option I want.
Lets say I will use “/localPageURL: another page on your site” The button will take user to another page on my site, but I want this link to change depending on which product user has open in store. if i use “/localPageURL: another page on your site” on product page it will take user to one page every time, no matter what product he/she is looking at

You can set the button’s link to whatever you want based on the the product that user has opened using the getProduct API . Then, based on which product collections the product is in, you can set the Button’s link to the page for that collection (category). If it’s in more than one collection, you can randomly choose one.

Would you be able to show the code for this? This is exactly what I’ve been looking for