admin管理员组文章数量:1415653
We have the "Shipping tax class" option on "Shipping tax class based on cart items".
When I add a free tax product to the shopping cart and a 21% tax product to the shopping cart together, the total tax for the shipment is 0.
That is incorrect because it should be 21%.
When I add only one product to the shopping cart it uses the correct tax, but not with 2 products of differtent taxe rates.
We have the "Shipping tax class" option on "Shipping tax class based on cart items".
When I add a free tax product to the shopping cart and a 21% tax product to the shopping cart together, the total tax for the shipment is 0.
That is incorrect because it should be 21%.
When I add only one product to the shopping cart it uses the correct tax, but not with 2 products of differtent taxe rates.
1 Answer
Reset to default 0I have found the answer by override the shipping tax filter
// 0% and 21% tax producdts added combined to the cart needs to have 21% shipping tax
add_filter('woocommerce_shipping_packages', 'override_woocommerce_shipping_packages');
function override_woocommerce_shipping_packages($packages) {
$shipment_needs_tax = false;
foreach ($packages[0]['contents'] as $cartitem) {
if (!empty($cartitem['data']->tax_class)) $shipment_needs_tax = true;
}
if ($shipment_needs_tax && empty($packages[0]['rates']['flat_rate:3']->get_taxes())) {
$shipcost = $packages[0]['rates']['flat_rate:3']->get_cost();
$shiptax = $shipcost * 0.21;
if ($shiptax > 0) $packages[0]['rates']['flat_rate:3']->set_taxes([4 => $shiptax]);
}
return $packages;
}
本文标签: phpWoocommerceShipping tax class based on cart items not using the highest tax available
版权声明:本文标题:php - Woocommerce - Shipping tax class based on cart items not using the highest tax available 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745150644a2644904.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论