У меня есть этот код ниже, но я хочу, чтобы он действовал только в том случае, если пользователь не использует другой код, и если пользователь использует другой купон, отключите его.
на основе " Применить скидку для определенной роли пользователя в Woocommerce" код ответа, я пытался посмотреть, как проверить, есть ли купон, но не могу его выяснить.
// Applying conditionally a discount for a specific user role
add_action( 'woocommerce_cart_calculate_fees', 'discount_based_on_user_role', 20, 1 );
function discount_based_on_user_role( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return; // Exit
// Only for 'company' user role
if ( ! current_user_can('affiliate') )
return; // Exit
// Only for 'company' user role
if ( ! current_user_can('affiliate') )
return; // Exit
// HERE define the percentage discount
$percentage = 15;
$discount = $cart->get_subtotal() * $percentage / 100;
// Applying discount
$cart->add_fee( sprintf( __("Affiliate Discount (%s)", "woocommerce"), $percentage . '%'), -$discount, true );
}
Любая помощь приветствуется.