jQuery   发布时间:2022-04-19  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jquery – 当数量选择改变时,WooCommerce显示总价大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
数量变化时,我需要在产品页面显示总价格.
如果您在购物车中添加产品数量,这与购物车中的行价相同.
我还是WooCommerce的新手,所以我不知道从哪里开始.但如果有人能帮助我找到正确的方向,我想我可以自己管理.

所以这是我对如何做的想法.

我在想我的jquery是这样的.

jQuery(document).ready(function($){
    $('.qty').on('change',function(){
         // grab the price
         var price = $('[itemprop="price"]').attr('content');
         var @R_980_10586@l_price = price * this.value;
         console.log(price,this.value,@R_980_10586@l_pricE);
    });
})

这在粘贴在控制台上时有效.但我不确定将此代码放在WooCommerce上的哪个位置.

解决方法

你几乎就在那里……试试这个,把它粘贴在你的functions.PHP

add_action( 'woocommerce_single_product_sumMary','woocommerce_@R_980_10586@l_product_price',31 );
function woocommerce_@R_980_10586@l_product_price() {
    global $woocommerce,$product;
    // let's setup our divs
    echo sprintf('<div id="product_@R_980_10586@l_price" style="margin-bottom:20px;">%s %s</div>',__('Product @R_980_10586@l:','woocommerce'),'<span class="price">'.$product->get_price().'</span>');
    ?>
        <script>
            jQuery(function($){
                var price = <?PHP echo $product->get_price(); ?>,currency = '<?PHP echo get_woocommerce_currency_symbol(); ?>';

                $('[name=quantity]').change(function(){
                    if (!(this.value < 1)) {

                        var product_@R_980_10586@l = parseFloat(price * this.value);

                        $('#product_@R_980_10586@l_price .price').html( currency + product_@R_980_10586@l.toFixed(2));

                    }
                });
            });
        </script>
    <?PHP
}

来源:http://reigelgallarde.me/programming/show-product-price-times-selected-quantity-on-woocommecre-product-page/

jquery – 当数量选择改变时,WooCommerce显示总价

大佬总结

以上是大佬教程为你收集整理的jquery – 当数量选择改变时,WooCommerce显示总价全部内容,希望文章能够帮你解决jquery – 当数量选择改变时,WooCommerce显示总价所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。