Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Display dynamic product variant price in javascript variable on product page

Display dynamic product variant price in javascript variable on product page

product-airpay
Shopify Partner
5 0 1

Since liquid is a server side language I'm having difficulty getting the actual Product price when out of Multiple product variants one is chosen. Can anyone let me know how to get accurate price of Product variant when chosen  from multiple options respectively. Based on the product option the Product price needs to be given to javascript variable so that it can be used in client side.

Reply 1 (1)

tobebuilds
Shopify Partner
478 34 129

Why not just use Liquid to generate a JSON object containing all the variants?

 

You could use a for loop, and emit an array containing each variant's iD, title, price, and compare at price.

Founder, Regios Discounts app (4.9 stars, 68 reviews, Built for Shopify)
- Custom discounts made simple
- "Just about any discount you'll ever need"
- Built by an ex-Google software engineer