【问题标题】:$cart->add_fee max out at 100$cart->add_fee 最高 100
【发布时间】:2022-01-25 10:04:49
【问题描述】:

我想从购物车总额中扣除 200 元。为此,我有这个代码。但它只从每个购物车项目中扣除 100。这是为什么呢?

function correction_of_deposit_cart( $cart ) {
  $cart->add_fee( __( 'Correction', 'correctionofdeposit' ) , -200 );
}
add_action( 'woocommerce_cart_calculate_fees', 'correction_of_deposit_cart' );

【问题讨论】:

  • 实际上它以小计的数量最大化。因此,如果小计为 130,则即使在代码中放入 200,它也会最大为 130。

标签: php wordpress woocommerce


【解决方案1】:

请试试这个:

function addDiscount($cart){
    $discount = 200;
    $cart->add_fee('Member discount', -$discount, false, 'zero-rate');
}

add_action('woocommerce_cart_calculate_fees', 'addDiscount');

&这个:

// exclude discount from taxes
function excludeCartFeesTaxes($taxes, $fee, $cart){
    return [];
}

add_action('woocommerce_cart_totals_get_fees_from_cart_taxes', excludeCartFeesTaxes', 10, 3);

更多详情:https://github.com/woocommerce/woocommerce/issues/21148

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-08
  • 2010-09-06
相关资源
最近更新 更多