Reputation: 27
I need your expertise because what am trying to do is to convert the JS Calculation price to a different currency.
Cart/checkout Price are changing to the correct currency using any currency converter plugin but if you're in the product single page the total price is not converting to the correct currency only the symbol is changing
JS Computation and to output to the html i used this because customer can change date and re calculate again
$('h3.booking_cost span').html(formatCurrency(cost * selected_qty));
$('.total-rental-price h2').html(formatCurrency(cost * selected_qty));
How can i convert the whole price in the single page not only the currency symbol
HTML output from the js computation
<div class="price total-rental-price">
<h2></h2>
</div>
I can convert any price if its only PHP but im using JS for the computation and i need your help because even i tried to input the variable from js to php it will not work because the user can change the date:
<?php echo wc_price( $AnyValueicanconvertusingths ); ?>
Additional Note: I'm using WooCommerce for this shop and my custom JS for the calculation and currency converter any WooComerce converter plugin
As you can see the price is not converted only the currency symbol changed
Upvotes: 0
Views: 1242
Reputation: 2751
I'm not familiar with WooCommerce, but if the problem is: you may calculate something on back end (php) and want to use it on front end (JS).
In PHP file inside <javascript>
section, put following
var priceMap = {usd:<?=wc_price_usd()?>, euro:<?=wc_price_euro()?>,.....
On client side it will look like:
var priceMap = {usd:123, euro:111,.....
So you may use any of currencies like so:
var currency = 'usd'
// ...
var myPrice = priceMap[currency]
Upvotes: 0