PDP update price when change quanty

<?php 
// update price
add_action( 'woocommerce_single_product_summary', 'tzn_custom_woocommerce_total_product_price', 90 );
function tzn_custom_woocommerce_total_product_price() {
    global $woocommerce, $product;
    ?>
        <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);
                        $('.single .price.product-page-price span.amount').html('<bdi>'+product_total.toLocaleString('de-DE', { minimumFractionDigits: 2 })+' <span class="woocommerce-Price-currencySymbol">'+currency+'</span></bdi>');

                    }
                });
            });
        </script>
    <?php
}

Leave a Reply

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