Sop*_*hie 5 jquery woocommerce
当数量变化时,我需要在产品页面中显示总价格.
如果您在购物车中添加产品数量,这与购物车中的行价相同.
我还是WooCommerce的新手,所以我不知道从哪里开始.但如果有人能帮助我找到正确的方向,我想我可以自己管理.
所以这是我对如何做的想法.
我在想我的jquery会是这样的.
jQuery(document).ready(function($){
$('.qty').on('change',function(){
// grab the price
var price = $('[itemprop="price"]').attr('content');
var total_price = price * this.value;
console.log(price, this.value, total_price);
});
})
Run Code Online (Sandbox Code Playgroud)
这在粘贴在控制台上时有效.但我不确定将此代码放在WooCommerce上的哪个位置.

Rei*_*gel 11
你几乎就在那里......试试这个,把它粘贴在你的functions.php中
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;">%s %s</div>',__('Product Total:','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_total = parseFloat(price * this.value);
$('#product_total_price .price').html( currency + product_total.toFixed(2));
}
});
});
</script>
<?php
}
Run Code Online (Sandbox Code Playgroud)
来源:http://reigelgallarde.me/programming/show-product-price-times-selected-quantity-on-woocommecre-product-page/
