在 Woocommerce 中我使用 Woocommerce One Page Checkout插件,我想在总计上添加 10% 的 GST。
以下是一个示例(总计不含 10% 的商品及服务税):
Cart Total: $200
Delivery charges: $20
Grand Total: $220
结果应如下所示(总计 10% GST):
Cart Total: $200
Delivery charges: $20
Grand Total: $242 (including 10% of cart total + 10% on Delivery)
在产品列表页面上,我做了以下操作来显示我想要的总数:
$woocommerce->cart->total = $woocommerce->cart->total + number_format(($woocommerce->cart->total * 10) /100, 2);
The problem is that when I place an order, I have a grand total of
$220
instead of$242
on the payment page.
如何在此处更新订单总额?
有什么办法可以对 Woocommerce 中的购物车总额征收 10% 的商品及服务税吗?
注意:我尝试使用网络调用对其进行调试,发现 Woocommerce 正在发送购物车数组,其中包含所有具有总计的产品,并且订单页面可能会再次计算总计(不包括我使用应用的 GST)以上代码块。
最佳答案
以下代码将为总计添加 10%:
add_filter( 'woocommerce_calculated_total', 'custom_cart_grand_total', 20, 2 );
function custom_cart_grand_total( $total, $cart ) {
return $total * 1.10;
}
代码位于事件子主题(或事件主题)的 function.php 文件中。经过测试并有效。
关于php - 向 Woocommerce 中的总计添加百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50482420/