【问题标题】:Disable tax calculation on a discount using the Fee Api in Woocommerce使用 Woocommerce 中的费用 API 禁用折扣税计算
【发布时间】: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


    【解决方案1】:

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

    但在那种情况下税款总是在使用负数时应用,所以WC_Cart add_fees() method中的第三个参数$taxable总是正确的 即使您将其设置为 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
    享受百分比折扣,但在使用优惠券时也会产生税费。

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

    【讨论】:

      猜你喜欢
      • 2018-03-02
      • 2013-10-08
      • 1970-01-01
      • 2014-02-12
      • 2020-09-16
      • 2014-03-28
      • 1970-01-01
      • 1970-01-01
      • 2021-11-23
      相关资源
      最近更新 更多