WooCommerce total price display when changing quantity selection

I need to display the total price on the product page when the quantity changes.
This is the same as the price of the line in the basket if you add the quantity of goods to the basket.
I'm still new to WooCommerce, so I'm not sure where to start. But if someone can help me in the right direction, I think I can handle it on my own.

So, here are my thoughts on how to do this.

I think my jquery will be like that.

jQuery(document).ready(function($){
    $('.qty').on('change',function(){
         // grab the price
         var price = $('[itemprop="price"]').attr('content');
         var total_price = price * this.value;
         console.log(price, this.value, total_price);
    });
})

this works when pasted to the console. But I'm not sure where to put this code on WooCommerce.

http://i.stack.imgur.com/uTfEy.png

+4
source share
2 answers

... , functions.php

add_action( 'woocommerce_single_product_summary', 'woocommerce_total_product_price', 31 );
function woocommerce_total_product_price() {
    global $woocommerce, $product;
    // let 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
}

: http://reigelgallarde.me/programming/show-product-price-times-selected-quantity-on-woocommecre-product-page/ enter image description here

+7

.

, ( ), .

:

jQuery(document).ready(function($){

  // grab the price
  var initial_price = $('[itemprop="price"]').attr('content');

  $('.qty').on('change',function(){
     var total_price = initial_price * this.value;
     console.log(initial_price, this.value, total_price);
  });

})

:

.

, .

0

All Articles