在单个产品页面中显示价格*数量

时间:2019-12-19 08:01:32

标签: woocommerce

我想在price * quantity单个产品页面中显示woocommerce。以下代码可以正常使用,但在数量不变之前,显示NANprice

    add_action( 'woocommerce_before_add_to_cart_button', 'woocommerce_total_product_variation_price' );
    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>',__(' price:','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(3);
                var product_total3 = product_total2.toString().replace(/\./g, ',');

                jQuery('#product_total_price .price').html( product_total3 + ' ' + currency );
            }

            jQuery('[name=quantity]').change(function(){
                priceformat();
            });

            jQuery('body').on('change','.variations select',function(){
                priceformat();              
            });

            priceformat();

        });
    </script>

<?php }

0 个答案:

没有答案