【问题标题】:Woocommerce tax rounding issueWoocommerce 税收四舍五入问题
【发布时间】:2016-03-27 00:22:57
【问题描述】:
我的 WooCommerce 商店中有一件商品价格为 24.17(不含税)。我的税率设置为 20%。
如果我将这些产品中的 3 件添加到我的购物车中,那么我的总税费为 87.01 英镑,而我预计会得到 87 英镑。
24.17 加上 20% 是 29.004 英镑,为什么不四舍五入到 29.00 英镑?
【问题讨论】:
标签:
php
wordpress
woocommerce
【解决方案1】:
当 WooCommerce 计算税收时,它首先将不含税的价格乘以订购的数量。因此,就 WooCommerce 而言,征税的价格为 72.51 英镑。它将这个值增加了 20%。然后,您将获得 87.012 英镑。正是这个最终数字向下舍入为 87.01 英镑。
以数学方式证明:
24.17 x 3 x (1 + 0.2) = 87.012.
如果您希望 WooCommerce 更改其计算税款的方式,您必须将代码添加到您的 functions.php 文件中。它可能看起来有点像以下:
add_filter( 'woocommerce_get_price_excluding_tax', 'custom_edit_price_function',10,3);
function custom_edit_price_function($price, $qty, $product) {
//calculate price how you like it here.
return $price;
}