📅  最后修改于: 2022-03-11 14:58:17.433000             🧑  作者: Mango
add_action( 'woocommerce_before_calculate_totals', 'one_applied_coupon_only', 10, 1 );
function one_applied_coupon_only( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
return;
// For more than 1 applied coupons only
if ( sizeof($cart->get_applied_coupons()) > 1 && $coupons = $cart->get_applied_coupons() ){
// Remove the first applied coupon keeping only the last appield coupon
$cart->remove_coupon( reset($coupons) );
}
}