在Woocommerce中使用Fee Api禁用折扣的税款计算

时间:2018-11-08 23:00:38

标签: php wordpress woocommerce cart discount

我正在使用自定义费用来根据购物车中的物品数量计算折扣。 如果购物车中有更多产品,折扣会更多。

两种产品的折扣应为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);
}

有人可以帮忙从费用中扣除税款吗?

1 个答案:

答案 0 :(得分:0)

可以对Fee API进行调整,以使用负费用进行折扣,就像您的代码一样。

  

但是在这种情况下,当使用负数时,总是会征税 ,因此WC_Cart add_fees() method中的第三个参数 $taxable 始终为true ,即使将其设置为false。
  参见:Apply a discount on the cart content total excluding taxes in WooCommerce

这种情况无法解决,因为WC_Cart Fee API是针对费用而非折扣的。

您可以使用Apply automatically a coupon based on specific cart items count in Woocommerce
并享受一定的折扣,但使用优惠券时也要缴税。

因此,如果不同时取消税收,就无法获得折扣。