Getting product variant price dynamically

Hello,

On the Shopify product page, I have different price variants, and I would like to be able to retrieve the price of the variant selected by the user.

How can I do that?

This is my code at the moment in main-product.liquid and I’m using Dawn theme:

The variable ‘price’ does not update correctly.

Thanks for support.

Alot of themes emit their own change event hunt for that and use it.

Try the code without the DOMContentLoaded in browser devtools console panel.

Ensure the element actually exists some themes do wonky things.

Ensure your selectors are targeting the correct element, either specific tag or that there are not multiples and your getting the wrong one. etc etc etc

Sight unseen the code seems fine but who knows what else is going on in your theme because you did not provide any inspectable urls so it will always be completed guessworkd for other people.

READ: https://community.shopify.com/post/2254458

Thank you for the support. I’m adding more information about my issue.


    

My site: https://www.luisjw.it/en/products/copia-del-cuore-anatomico-xl?variant=47226652590418

1 Like

@gtn-dev Hey
Found the Solution, yet?

check out my solution above

Thank you for your response @btromero

Here is my code, I want to show the selected variation price discount.
How to apply your solution for my code. Can you help please?

BEST PRICE: Rs.{{ product.price | divided_by: 100 | times: 0.80 | round }}

Its working like a charm. @btromero I don’t know how to thank you. I really appreciate your help.

@btromero
When going to the product page, It calculates the discounts as per the lowest price first, so if the largest priced variation is selected by default it will show the discounted price of the lowest variation. When we select the other variations then it shows the proper prices. Can we fix it?

Also can we show the store currency here instead of Rs. : Rs.{{
product.price | divided_by: 100 | times: 0.80 | round }}

Thank you,

@btromero Thank you. Actually I am not a programmar and couldn’t understand what to do. I tried somethings from above solution. Also tried Chatgpt to solve it according to your solution, but nothing is working. Can you provide the script with the changes? It’ll be helpful.
Thanks