Assuming that you got the “current_variant” variable from the “selected_or_first_available_variant” attribute of the product object, it might be the reason for your problem. Liquid is preprocessed (compiled), so it can’t track the changes after the code it generates is sent to the browser. In other words, the aforementioned attribute returns the first available variant until the page is refreshed. Once you refresh the product page, it would parse the active variant ID based on the product URL and your code should display the correct saving amount.
However, refreshing the product page every time a different variant is selected doesn’t seem to be a great idea. The problem is that there’s no change event for the option (variant) selector elements. You may want to create your own event listener to track the variant selection. Luckily, I managed to find a solved thread dedicated to a pretty similar issue.
That is not the problem.
My issue is that I can’t address the metafield in javascript.
The price updates every time I change the variant, I have already solved this problem.
My problem right now is that I don’t get a return value when I address my metatag in my Theme.js.
This is my metatag: variant.metafields.my_fields.months
In my product-template.liquid I get a value back, but this does not work in Theme.js
Is there another variable needed here or do I still need to define it?
I hope you understand my problem
Oh, I see. I’ve been playing around with a similar thing on my dev store and ended up creating a hidden block on the product page to keep the variants data in form of a JSON object:
The code was working in every browser except Safari on my Iphone.
The reason was that the variant_id was automatically detected as phone number “tel.132566565156312” so javascript was not able to find the matching variantid.
By adding the following code to your product page Safari stops this behavior:
I understand what you are doing, but it seems t miss a call to the variantsmetafields code. Can you please explain how to actually display the information?