Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Apply a Discount Based on User Role and Payment Method in WooCommerce ?

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).

How to Apply a Discount Based on User Role and Payment Method in WooCommerce ? - Tyche Softwares

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.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
Valentine’s Day Big Hearts, Better Savings Sale: 20% Off on All Plugins. 25% Off on All Plugin Bundles.
0
Would love your thoughts, please comment.x
()
x
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible.

Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

By using our site, you acknowledge that you have read and understood our Privacy Policy and Terms & Conditions.