mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-05-03 12:12:25 +08:00
https://stackoverflow.com/questions/35669568/woocommerce-display-total-price-when-quantity-selection-change/
24 lines
955 B
Text
24 lines
955 B
Text
add_action( 'woocommerce_single_product_summary', 'woocommerce_total_product_price', 31 );
|
|
function woocommerce_total_product_price() {
|
|
global $woocommerce, $product;
|
|
// let's setup our divs
|
|
echo sprintf('<div id="product_total_price" style="margin-bottom:20px;">%s %s</div>',__('Product Total:','woocommerce'),'<span class="price">'.$product->get_price().'</span>');
|
|
?>
|
|
<script>
|
|
jQuery(function($){
|
|
var price = <?php echo $product->get_price(); ?>,
|
|
currency = '<?php echo get_woocommerce_currency_symbol(); ?>';
|
|
|
|
$('[name=quantity]').change(function(){
|
|
if (!(this.value < 1)) {
|
|
|
|
var product_total = parseFloat(price * this.value);
|
|
|
|
$('#product_total_price .price').html( currency + product_total.toFixed(2));
|
|
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
<?php
|
|
}
|