Viewing 1 replies (of 1 total)
  • Thread Starter Gianluca

    (@karnhack)

    I partially solved the problem with this code in function.php, but it does not work properly because it ignores “variable product price”
    can someone help me
    thanks

    // we are going to hook this on priority 31, so that it would display below add to cart button.
    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:none">%s %s</div>',__('Product Total:','woocommerce'),'<span class="price">'.$product->get_price().'</span>');
        echo sprintf('<div id="cart_total_price" style="margin-bottom:20px;display:none">%s %s</div>',__('Cart Total:','woocommerce'),'<span class="price">'.$product->get_price().'</span>');
        ?>
            <script>
                jQuery(function($){
                    var price = <?php echo $product->get_price(); ?>,
                        current_cart_total = <?php echo $woocommerce->cart->cart_contents_total; ?>,
                        currency = '<?php echo get_woocommerce_currency_symbol(); ?>';
    
                    $('[name=quantity]').change(function(){
                        if (!(this.value < 1)) {
                            var product_total = parseFloat(price * this.value),
                            cart_total = parseFloat(product_total + current_cart_total);
    
                            $('#product_total_price .price').html( currency + product_total.toFixed(2));
                            $('#cart_total_price .price').html( currency + cart_total.toFixed(2));
                        }
                        $('#product_total_price,#cart_total_price').toggle(!(this.value <= 1));
    
                    });
                });
            </script>
        <?php
    }
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘View total in single_product before adding to cart’ is closed to new replies.