【发布时间】:2019-04-12 12:50:54
【问题描述】:
我正在使用自定义费用来根据购物车中的商品数量计算折扣。 如果购物车中有更多产品,折扣会更多。
2 件产品的折扣应为 5 欧元,但折扣为 6.05 欧元,因为 21% 的税是在折扣金额上计算的。
我使用的代码如下
// Hook before calculate fees
add_action('woocommerce_cart_calculate_fees' , 'add_custom_fees');
/**
* Add custom fee bij meer dan 2 artikelen
* @param WC_Cart $cart
*/
function add_custom_fees( WC_Cart $cart ){
if( $cart->cart_contents_count < 2 ){
return;
}
//$Korting = Winkelwagen geteld * 5) - 5 (-5 is om eerste product korting te verwijderen;
// Calculate the amount to reduce
$discount = ($cart->get_cart_contents_count() * 5) -5;
$cart->add_fee( 'Sinterklaaskorting', -$discount, false);
}
有人可以帮助从费用中扣除税款吗?
【问题讨论】:
标签: php wordpress woocommerce cart discount