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

How to Waive Payment Gateway Fee if Coupon Is Applied?

Typically, WooCommerce store owners offer multiple payment methods — and some, like certain digital wallets, come with higher transaction fees. To recover these additional costs without raising prices for everyone, you can apply a handling fee based on the selected payment method — but waive it when a coupon is applied.

For instance, you might add a $2.99 handling fee when PayPal is selected, unless a discount coupon is active. This helps offset processing fees while still offering a smooth, value-driven checkout experience for customers using coupons.

Solution: Waive Payment Gateway Fee if Coupon Is Applied

The fee is only applied when a specific payment method is chosen and no discount is active

add_action( 'woocommerce_cart_calculate_fees', 'ts_custom_paypal_fee_no_coupon', 20, 1 );

function ts_custom_paypal_fee_no_coupon( $cart ) {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
        return;
    }

    // Make sure WooCommerce session is available
    if ( ! WC()->session ) {
        return;
    }

    // Only apply fee if PayPal is the selected payment method
    $chosen_gateway = WC()->session->get( 'chosen_payment_method' );

    // Exit if a coupon is applied
    if ( $cart->has_discount() ) {
        return;
    }

    // List of gateways to charge fee (you can add more)
    if ( $chosen_gateway === 'ppcp-gateway' ) {
        $fee_amount = 2.99; // Set your fee
        $cart->add_fee( __( 'PayPal Handling Fee', 'woocommerce' ), $fee_amount, false );
    }
}
add_action( 'wp_footer', 'ts_refresh_cart_on_payment_method_change' );
function ts_refresh_cart_on_payment_method_change() {
    if ( is_checkout() && ! is_wc_endpoint_url() ) : ?>
    <script type="text/javascript">
        jQuery(function($) {
            $('form.checkout').on('change', 'input[name="payment_method"]', function() {
                $('body').trigger('update_checkout');
            });
        });
    </script>
<?php endif;
}

Output

When a customer selects the PayPal payment gateway, a fee of $2.99 is applied at checkout. However, if a coupon is applied to the cart, the fee is waived automatically.

Waive Payment Gateway Fee if Coupon Is Applied

Want to recover higher processing costs from specific customer roles? In that case, adding checkout fees based on both the selected payment gateway and the user role in WooCommerce is a smart move.

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

Share It:

Subscribe
Notify of
0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
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.