0

I'm trying to adapt a script that I had taken from another stack answer that changes the total price when quantity selection change. The script below only shows the price change with tax, how do I display with and without tax?

/**
* WooCommerce display total price when quantity selection change
* https://stackoverflow.com/questions/35669568/woocommerce-display-total-price-when-quantity-selection-change
*/


add_action( 'woocommerce_after_add_to_cart_button', '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" class="d-inline-block ml-md-2">%s %s</div>',__('Quantity Total:','woocommerce'),'<span class="qty-price fw-bold">'.$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 .qty-price').html( currency + product_total.toFixed(2));

                    }
                });
            });
        </script>
    <?php
}
Amesey
  • 822
  • 2
  • 16
  • 33
  • 1
    https://stackoverflow.com/questions/37227730/display-woocommerce-product-price-with-and-without-tax-and-tax-amount – Snuffy Jun 13 '22 at 14:28
  • Thanks, this helped, although I am left with a rounding issue, time for a new post. – Amesey Jun 14 '22 at 15:21

0 Answers0