mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-30 11:42:22 +08:00
https://businessbloomer.com/woocommerce-calculate-subtotal-on-quantity-increment-single-product/
16 lines
649 B
Text
16 lines
649 B
Text
add_action( 'woocommerce_after_add_to_cart_button', 'wc_product_price_recalculate' );
|
|
|
|
function wc_product_price_recalculate() {
|
|
global $product;
|
|
echo '<div id="subtot" style="display:inline-block;">Total: <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(2);
|
|
$('#subtot > span').html('" . esc_js( $currency ) . "'+price_string);
|
|
}).change();
|
|
" );
|
|
}
|