Php 使用“woocommerce\u cart\u total”计算折扣价格,未更新总税额
我正在使用Php 使用“woocommerce\u cart\u total”计算折扣价格,未更新总税额,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我正在使用woocommerce\u cart\u total操作钩子在客户退房之前使用自定义折扣更新购物车的总价格。这导致了两个问题: 结帐窗口中的总金额在折扣保持不变的情况下更新,但税收总额仍基于旧金额。如何根据新的总金额更新/计算总税额 总金额在结帐窗口中显示正确,但在“谢谢”页面和WP Admin Order页面中,显示并从客户处捕获的是旧的总金额(无折扣) 以下是我目前使用的代码。global$customDiscount在cart/review order.php模板文件中设置,
woocommerce\u cart\u total
操作钩子在客户退房之前使用自定义折扣更新购物车的总价格。这导致了两个问题:
global$customDiscount
在cart/review order.php
模板文件中设置,如果购物车中有x个数量的产品,则激活该模板
add_action('woocommerce_cart_total', 'calculate_totals', 10, 1);
function calculate_totals($wc_price){
global $customDiscount;
$old_total = WC()->cart->cart_contents_total + WC()->cart->tax_total;
$new_total = $old_total - $customDiscount;
return wc_price($new_total);
}
我还尝试将折扣计算本身从
review order.php
-文件中移出,并将其放入calculate\u totals
函数中,但没有任何区别。