PressTigers

How to show Total Product Price w.r.t Quantity in WooCommerce

WooCommerce (the best shopping cart plugin) gives store owners a complete control of all the customizable features to add strength to their online product stores/business. In products detail page, a user may require to show total price of the product on detail page when he/she orders a product with more than 1 quantity.

For instance, if you want to buy 2 watches for $100 each then the total cost will be $200. Similarly if you change the quantity of the product more than 2, then it will show the total cost according to the selected quantity of the product.

To achieve this functionality, use the Hook of WooCommercewoocommerce_single_product_summary”. You can see this hook in content-single-product.php template file. Many functions bind with this hook and it is called on product detail page.

When a function is added in this hook , a priority has been assigned to that function. Function with a high priority will call first. For adding the functionality, add this particular function after “woocommerce_template_single_add_to_cart” which has a hook priority of 30 and the function will be called after this.

Paste the following code in functions.php file of your Theme or Child Theme:

User Comments

14 thoughts on “How to show Total Product Price w.r.t Quantity in WooCommerce

    Mihaela says:

    It is not working for me… I get a 500 error… “is currently unable to handle this request.” What should I do? I pasted the code in child theme

      Hi Mihaela,

      We have tested this code in our shopping cart and it’s working fine. No error was found due to this code snippet.

      Kindly re-check your code. You might have made some other changes in WooCommerce.

      Thanks,


      Yours truly,
      Sehrish Iftikhar
      Level lll Support

    Kyle Lynn says:

    Would this type of thing work with a variable product?

    I’ve been looking for a solution that shows the total price when selecting multiple quantities of a variable product.

    When using this code it calculates the total based on the minimum price of the variable product as a whole.

      Dear Kyle,

      Yes, your are right! It will not work with variable products.

      Actually this code snippet is only workable for simple products. But you can customize this code for variable products.

      Good Luck!

      Thanks,

      Yours truly,
      Sehrish Iftikhar
      Level lll Support
      Email: support@presstigers.com | URL: https://presstigers.com

        Paul says:

        Looked for a solution to..

        I tried with:

        [quote]
        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(‘%s %s’,__(‘Totaal Prijs:’,’woocommerce’),’‘.$product->get_price().’‘);
        ?>

        jQuery(function($){
        var price =
        console.log(price);
        var currency = ”;

        $(‘[name=quantity]’).change(function(){
        var product_total = parseFloat(price * this.value);
        $(‘#product_total_price .price’).html( currency + product_total.toFixed(2));

        });
        });

        <?php
        }
        [/quote]

        But I don't get the current selected variation product price -.-..

        ashu says:

        can you please provide code which will work for variable product also.

        Thanks in advance

          Hello Ashu,

          This code only works for simple products not for variable products. You can explore WooCommerce plugin to get the variable product price w.r.t quantity.

          Thanks & Regards,
          Abdullah | WP Plugin Developer
          Email: support@presstigers.com

            ashu says:

            I don’t think there are any plugin with that functionality. I would like to purchase extension if any.

            Hello Ashu,

            Current, there is no extension available but our WP specialists can review your modifications and these efforts will be paid at cost 18/hours.

            Let us know if you want to proceed then accordingly we will provide you an estimate for your custom task.

            Thank you!

            Regards,

            Sehrish | WP Plugin Developer
            Email: support@presstigers.com

        Vigneshraja K says:

        please give me the customized code for variable product

    Dave Ackermann says:

    This article just saved my life! Thanks so much to the authors for making it SOOOO easy to implement. It works flawlessly and literally, all i had to do was copy and paste the code! Well done! Thanks so much!

    Vigneshraja K says:

    i need code snippet for variable products

Leave a Reply

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

Get in Touch