Quote from Mandy on November 26, 2023, 16:59
Hello,
I added the below code to my single product template to display the total.
how can I amend the code please to have the total amount converted as per the current currency selected?
Thanks
add_action( 'woocommerce_after_add_to_cart_button', 'bbloomer_product_price_recalculate' );
function bbloomer_product_price_recalculate() {
global $product;
echo '<div id="subtot" style="display:inline-block;"><div class="tottit">Total</div> <span></span></div>';
$price = $product->get_price();
$currency = get_woocommerce_currency_symbol();
wc_enqueue_js( "
$('[name=quantity]').on('input change', function() {
var qty = $(this).val();
var price = '" . esc_js( $price ) . "';
var price_string = (price*qty).toFixed(0);
$('#subtot > span').html('" . esc_js( $currency ) . "' +price_string);
}).change();
" );
}
Hello,
I added the below code to my single product template to display the total.
how can I amend the code please to have the total amount converted as per the current currency selected?
Thanks
add_action( 'woocommerce_after_add_to_cart_button', 'bbloomer_product_price_recalculate' );
function bbloomer_product_price_recalculate() {
global $product;
echo '<div id="subtot" style="display:inline-block;"><div class="tottit">Total</div> <span></span></div>';
$price = $product->get_price();
$currency = get_woocommerce_currency_symbol();
wc_enqueue_js("
$('[name=quantity]').on('input change', function() {
var qty = $(this).val();
var price = '" . esc_js( $price ) ."';
var price_string = (price*qty).toFixed(0);
$('#subtot > span').html('" . esc_js( $currency ) ."' +price_string);
}).change();
" );
}