在 Woocommerce 的总计中添加一个百分比
Add a percentage to the grand total in Woocommerce
在 Woocommerce 中,我正在使用 Woocommerce One Page Checkout 插件,我想在总计上添加 10% 的商品及服务税。
这是一个例子(总计没有 10% 的商品及服务税):
Cart Total: 0
Delivery charges:
Grand Total: 0
结果应该是这样的(总计有 10% 的 GST):
Cart Total: 0
Delivery charges:
Grand Total: 2 (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 0
instead of 2
on the payment page.
我如何在这里更新订单总数?
有什么办法可以对 Woocommerce 中的购物车总金额征收 10% 的 GST?
注意: 我尝试使用网络调用对其进行调试,发现 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 文件。已测试并有效。
在 Woocommerce 中,我正在使用 Woocommerce One Page Checkout 插件,我想在总计上添加 10% 的商品及服务税。
这是一个例子(总计没有 10% 的商品及服务税):
Cart Total: 0
Delivery charges:
Grand Total: 0
结果应该是这样的(总计有 10% 的 GST):
Cart Total: 0
Delivery charges:
Grand Total: 2 (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
0
instead of2
on the payment page.
我如何在这里更新订单总数?
有什么办法可以对 Woocommerce 中的购物车总金额征收 10% 的 GST?
注意: 我尝试使用网络调用对其进行调试,发现 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 文件。已测试并有效。