15.10.2017
Выводим базовую цену товара в WooCommerce:
<?php $product_id = get_the_ID(); $product = wc_get_product( $product_id ); echo $product->get_sale_price(); ?>
Выводим цену со скидкой, а если она не менялась, тогда выводим основную цену:
<?php $price = get_post_meta( get_the_ID(), '_regular_price', true); $sale = get_post_meta( get_the_ID(), '_price', true); if (!empty($sale)){ echo $sale; } else { echo $price; } ?>
Выводим общую стоимость товара при изменении количества
Такой вот получился код для Total Price в WooCommerce:
<div class="total-price"> <span class="total-title">Total Price</span> <span class="total-symbol">$</span><span class="total-amount"><?php $price = get_post_meta( get_the_ID(), '_regular_price', true); $sale = get_post_meta( get_the_ID(), '_price', true); if (!empty($sale)){ echo $sale; } else { echo $price; } ?></span> <span class="current-price hidden"><?php if (!empty($sale)){ echo $sale; } else { echo $price; } ?></span> </div>
И такой JS обрабатывает и выводит сумму:
(function quantityProducts() { $(".quantity").find("span").click(function () { var calc = $(this).parent().find(".qty"); var calcText = calc.val(); var price = $('.total-price .current-price'); var priceText = price.text(); var totalAmount = $('.total-price .total-amount'); if ($(this).hasClass("minus") && calcText > 1) { calc.val(+calcText - 1); var n = +priceText * (+calcText - 1); var n = Math.round(n * 100) / 100; totalAmount.text( n ); } else if ($(this).hasClass("plus")) { calc.val(+calcText + 1); var n = +priceText * (+calcText + 1); var n = Math.round(n * 100) / 100; totalAmount.text( n ); } }); })();
Выглядит это так: