我们已经使用$woocommerce->cart->add_fee()
方法向WooCommerce购物车添加了费用。
应用具有一定百分比折扣的WooCommerce优惠券代码时,在计算折扣时不会考虑费用金额。
例如:
Product Price: 15 Additional Fee: 5 Discount: 10%=> 1.5 (10% of 15) Total: 21.5但是我们需要它为
Product Price: 15 Additional Fee: 5 Discount: 10%=> 2 ( 10% of 15+5) Total: 22
找不到任何挂钩可以将费用包括在折扣计算过程中
答案 0 :(得分:0)
您需要钩上calculate_fee并进行相应的修改
add_action( 'woocommerce_cart_calculate_fees','wc_custom_surcharge', 10, 1 );
function wc_custom_surcharge( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
// HERE set your percent rate
$percent = 1; // 1%
// Fee calculation
$fee = ( $cart->subtotal - $cart->get_cart_discount_total() ) * $percent / 100;
// Add the fee if it is bigger than O
if( $fee > 0 )
$cart->add_fee( __('Surcharge', 'woocommerce'), $fee, true );
}