Menu Close

Calculate Subtotal On Quantity Increment in Woocommerce Single Product Page


Add below codes on your function.php file and get the sub total amount while customer increase the product quantity on the single product page.

add_action( 'woocommerce_after_add_to_cart_button', 'code_product_price_recalculate' );
function code_product_price_recalculate() {
   global $product;
   echo '<div id="subtotal" 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);
   " );

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?


Posted in WooCommerce, WordPress

Leave a Reply

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

You can also read...