Get product price in javascript

Highlighted
New Member
3 0 0

On my product page, I want to show what the instalments on an interest-free credit payment plan would look like.

 

With javascript this is quite simple to do the mathematical bit, but I need help either finding a javascript variable with a product's price or creating one?

 

Seeing as the price updates automatically with javascript when a variant is changed, I imagine that the variable may already be stored in the DOM?

 

0 Likes
Highlighted
Shopify Partner
270 26 42

Hi @adamscot92,

You must look for the variant selector on your theme.js file, variant.price is the code you need.

Let's make the best store!
Contact us at: thepremierstores@gmail.com
0 Likes
Highlighted

What I usually do is:

1. Go to theme.js (or the main Javascript file of the theme)
2. Look for a function called _updatePrice or something like this. 
3. Add a global variable to it, like this:

diego_ezfy_0-1605830409263.png


Then you can access the current variant's price no matter where you are with window.product_variant

 

◦ Problem Solved? ✔️ Please click on Accept as Solution and like.
◦ Needing urgent help? I am currently available for hire, same day response guaranteed: diego.boarutto.fortes@gmail.com
0 Likes