WooCommerce gives store owners a basic foundation to apply discounts, but it still lacks one practical feature many store owners need: a way to automatically apply a discount based on both the customer’s user role and the payment method selected at checkout.
Store owners often face two common issues:
- You want to incentivize certain payment methods (like Stripe or Credit Card) because they’re more reliable or cost you less in transaction fees.
- You want to reward specific user roles—such as subscribers or members—with a small, automatic discount, without creating separate coupons or discount rules.
However, WooCommerce doesn’t allow you to combine these two conditions out of the box.
In this guide, we solve exactly that problem using a simple snippet, where you can apply a discount based on both the customer’s user role and the payment method selected at checkout.
Solution: Apply a Discount Based on User Role and Payment Method in WooCommerce
This code automatically applies a percentage discount only when a specific user role selects certain payment methods during checkout. For example, this code gives subscribers an automatic 2% discount when they choose the PayPal or Cash on Delivery at checkout.
// Apply a discount based on user role and payment method
add_action( 'woocommerce_cart_calculate_fees', 'ts_role_payment_percentage_discount', 20, 1 );
function ts_role_payment_percentage_discount( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; // Exit in admin
// Only for subscribers
if ( ! current_user_can( 'subscriber' ) ) return;
// Get chosen payment method
$chosen_method = WC()->session->get( 'chosen_payment_method' );
if ( isset( $_POST['payment_method'] ) ) {
$chosen_method = sanitize_text_field( $_POST['payment_method'] );
}
// Define targeted payment methods
$targeted_payment_methods = array( 'ppcp-gateway' ); // PayPal Commerce
// Define percentage
$discount_percentage = 2; // 2%
if ( in_array( $chosen_method, $targeted_payment_methods ) ) {
$discount = $cart->get_subtotal() * ( $discount_percentage / 100 );
$cart->add_fee( sprintf( __( 'Discount (%s%%)', 'woocommerce' ), $discount_percentage ), -$discount, true );
}
}
// Refresh totals when payment method changes on checkout
add_action( 'woocommerce_review_order_before_payment', 'ts_refresh_checkout_on_payment_change' );
function ts_refresh_checkout_on_payment_change() {
?>
<script type="text/javascript">
jQuery(function($){
$('form.checkout').on('change', 'input[name="payment_method"]', function(){
$('body').trigger('update_checkout');
});
});
</script>
<?php
}
Output
When a subscriber visits your WooCommerce store and proceeds to checkout, this snippet ensures that they automatically receive a discount only if they select specific payment methods—in this case, PayPal or Cash on Delivery (COD).

Discounts based on user roles and payment methods can make checkout smoother for your customers. You can also explore scenarios where a free product or an additional discount is automatically added when someone buys a specific item or belongs to a particular user role. Plugins like Flexi BOGO for WooCommerce let you set up these kinds of offers, combining role-based and product-based conditions for a more personalized shopping experience.
