How to use {{{ data }}} value into a javascript variable?

I have a line of code which I think is a js template placeholder when I use it like this it returns the value that I need “the price of a product”

?>
{{{ data.variation.amz_price_var_uk }}}
<?php

i need to use the value of {{{ data.variation.amz_price_var_uk }}} and use it into a js variable, the problem is that if i typed the following it just render the exactly what inside the ” instead of returning its value, is there anyway to use the value of that line (sorry not sure what it’s called) and use it in a js variable other than capturing it’s value from its div since the value will be changing depending on the what the user will choose in a related select box.

?>
<script>
var price ‘{{{ data.variation.wccaf_de_asin_var }}}’;
document.getElementById(“amz_price_wrap”).insertAdjacentHTML(‘afterbegin’, price);
</script>
<?php

If you need more info about what i’m working on. i’m trying to add a custom price to a variation woocommerce product, the variation select box is using what’s so-called wp.template
https://codex.wordpress.org/Javascript_Reference/wp.template

i was sucessfully able to pass the price of variations to {{{ data.variation.amz_price_var_uk }}} which works perfectly in html but what i need to do is to pass it’s value to js variable so i can change the price based on the visitor location using a javascript/json api.

I think my last resort will be to print all prices for each country in html each price in a separate div and use js to show only the div that match the visitor country but i hope you can tell me a cleaner way.

Read more here:: How to use {{{ data }}} value into a javascript variable?

Leave a Reply

Your email address will not be published. Required fields are marked *