• Hi all,

    Does someone know how to get the variation price * qty?

    Got this code, but this is not working for me.

    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('<div id="product_total_price" style="margin-bottom:20px; display: block;">%s %s</div>',__('Totaal Prijs:','woocommerce'),'<span class="price">'.$product->get_price().'</span>');
        ?>
            <script>
                jQuery(function($){
                    var price = <?php get_post_meta( get_the_ID(), '_regular_price', true);?>
                    console.log(price);
                    var currency = '<?php echo get_woocommerce_currency_symbol(); ?>';
     
                    $('[name=quantity]').change(function(){
                            var product_total = parseFloat(price * this.value);
                            $('#product_total_price .price').html( currency + product_total.toFixed(2));
    						
     
                    });
                });
            </script>
        <?php
    }
    • This topic was modified 8 years, 5 months ago by venigo.
    • This topic was modified 8 years, 5 months ago by venigo.
    • This topic was modified 8 years, 5 months ago by venigo.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter venigo

    (@venigo)

    Solved after some trail and error.. Could be nicer, but it is working at my side.
    Note I am in the Netherlands we use the , instead of . (woocommerce is also configured on , as decimal..).

    Total price based on variation @ theme / functions.php

        // hook this on priority 31, display below add to cart button.
        add_action( 'woocommerce_single_product_summary', 'woocommerce_total_product_variation_price', 31 );
        function woocommerce_total_product_variation_price() {
        global $woocommerce, $product;
        // setup base html... We are going to rewrite this with the standard selected variation
        echo sprintf('<div id="product_total_price" style="margin-bottom:20px; display: block;">%s %s</div>',__('Totaal Prijs:','woocommerce'),'<span class="price">'.$product->get_price().'</span>');
        ?>
            <script>
                jQuery(function($){
    				
                var currency    = currency = ' <?php echo get_woocommerce_currency_symbol(); ?>';
     
    				function priceformat() {
    					var product_total = parseFloat(jQuery('.woocommerce-variation-price .amount').text().replace(/ /g ,'').replace(/€/g ,'').replace(/,/g ,'.')) * parseFloat(jQuery('.qty').val());
    					var product_total2 = product_total.toFixed(2);
    					var product_total3 = product_total2.toString().replace(/\./g, ',');
    					
    					jQuery('#product_total_price .price').html( currency + ' ' + product_total3);
    				}
     
                    jQuery('[name=quantity]').change(function(){
    					priceformat();
    		        });
    				
    				jQuery('body').on('change','.variations select',function(){
    					priceformat();				
    				});
    				
    				priceformat();
    				
                });
            </script>
        <?php }

    Hi. Very nice decision.
    But there are a few questions:
    1. Before select qty of product – total NaN
    2. If item sale – decision taking only regular price for calculating…

    • This reply was modified 8 years, 1 month ago by kalazar.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Woocommerce] Total price, get variation price * qty’ is closed to new replies.