WooCommerce payment gateway based fees and discounts

Two methods to add dynamic charges to the WooCommerce checkout

WooCommerce payment gateway based fees and discounts are an excellent way of incentivising or discouraging users from choosing certain methods of payment. They’re also an important way for you to ensure you don’t lose out through charges imposed by certain payment gateways.

WooCommerce payment gateway based fees and discounts

In this article, I’m going to look at two ways to apply WooCommerce payment gateway based fees and discounts:

  • Use a plugin to apply fees and discounts according to the payment gateway
  • Programmatically apply fees and discounts according to the payment gateway

By the way, if you’re looking specifically for adding a cash on delivery fee, take a look at this article.

What is a WooCommerce payment gateway?

The payment gateway is the method used by the customer to pay for their order. Examples are PayPal, Stripe (for credit card payments), bank transfer, cash on delivery, and many more.

Which payment gateway should I choose?

Which payment gateway you choose is going to be down to a number of factors, including:

  • Where you’re based – not all payment gateways are available in every country
  • How much you’re prepared to pay in fees – each gateway has a different fee structure
  • How much you want to spend on initial costs – some payment gateway plugins are free, others will cost you just to install them on your site

There’s a useful article by Kinsta here on some of the most popular and trusted WooCommerce payment gateways.

What do payment gateways cost?

Costs vary. For instance, PayPal can charge you up to 3.4% per transaction. That’s a big chunk of your profits.

On the other hand, if you offer BACS payments, Cash on Delivery, or other local pickup or collection options, you may not have any cost associated with the payment gateway.

This is the main reason you might want to levy a WooCommerce payment gateway based fee or discount – either to add a surcharge on the payment gateways that cost you extra. Or to offer a discount to customers if they use a cheaper payment method.

Not all gateways have costs attached

A really simple way of saving costs for yourself, as the business owner, and for your customers is to offer a collection option. Of course, this depends on the nature of your business but it works really well for stores that sell locally.

You can also offer bank transfer or cheque options. This increases the amount of manual work you need to do, and it slows down the overall process – but it does allow you to save some money.

Why use multiple gateways?

You might be thinking that it would just be simpler to only offer the cheapest payment gateways. Up to a point, that might be true. But there’s a good chance that you’ll miss out on sales if you don’t offer customers payment options that they’re familiar with.

For instance, although it’s expensive, PayPal is a really convenient option for many people to use for payment. They don’t need to find their credit card, they only need to click a button.

So having choice on your site can be to your benefit.

Why apply different charges according to the payment gateway used?

There are several reasons to apply different charges based on the payment gateway, including:

  • Credit card providers usually charge you a percentage of each transaction. You can recoup this fee by adding the equivalent amount to the cost of the order and therefore passing the transactional fees from your bank on to your customer.
  • PayPal charges you a fee on every transaction. You can add a flat fee or a percentage of the overall order total to recover this cost from the user.
  • With PayPal and credit card gateways, you can often find that you are subject to disputes or chargebacks. The costs for these vary between gateway providers but by adding a small surcharge to users who check out through one of these gateways, you can provide a small insurance for yourself against future disputes.
  • If you accept payment via BACS or bank transfer, you might be charged per transaction by your bank. You can add a small fixed fee to the cart to cover these bank charges.
  • You can offer incentives to your customers to pay by your preferred payment gateway by applying a discount. For instance, if you would like to encourage users to pay via bank transfer, you can offer a fixed or percentage discount.

Which is better – fee or discount?

Should you cost your products at a lower price, then add an extra fee for certain payment gateways? Or should you build the fees into your product price, then offer a discount if the customer chooses a less expensive payment gateway?

Good question – I wish I had the answer. I think this will depend on the type of business you’re running:

  • Pricing products lower is always a good encouragement for customers; but seeing an extra fee imposed at checkout can be a cause of cart abandonment
  • Having slightly more expensive products but a discount at checkout could be a pleasant surprise for customers

Using a plugin to apply fees and discounts based on payment gateway

However you decide to approach WooCommerce payment gateway based fees and discounts, you’ll need an extension to WooCommerce.

The WooCommerce payment gateway fees plugin that I’m using is WooCommerce Fees and Discounts.

I’m going to provide a couple of different examples using this plugin to show how to apply fees and discounts, either as fixed amounts or percentages of the overall total.

Install WooCommerce Fees and Discounts

  • Once you’ve downloaded the Fees and Discounts plugin, upload it to your WordPress admin via Plugins > Add New > Upload.
  • Activate the plugin then go to WooCommerce > Settings > Fees and Discounts.
  • Ensure that the ‘Enable Payment Gateway Fees and Discounts’ option is selected. You should see all the active payment gateways on your site available as clickable links below the main tabs.
WooCommerce payment gateways

You can set fees and discounts for each payment gateway separately.

How to add a fee to PayPal in WooCommerce

In this example, I’ll walk through charge to add a fixed fee to customers who check out via PayPal.

  • Click on the PayPal Checkout link
  • In ‘Label’ enter the text that you’d like to use to denote the extra charge
  • Choose ‘Fixed fee’ in the ‘Type’ dropdown
  • Enter the amount of the fixed fee in the ‘Amount’ field
  • Decide whether to include shipping costs in the cart total. (Note that this is mainly relevant if you’re charging a percentage rather than a fixed fee and/or if you are setting minimum or maximum values for the cart)
  • In ‘Minimum cart amount’, you can enter a minimum total for the cart before any charges are applied.
  • For ‘Maximum cart amount’, you can enter a maximum total for the cart above which no charges will be applied.
  • Check ‘Apply tax’ if you would like tax to be applied to the extra charge
  • Select the ‘Tax class’
  • Click ‘Save changes’
WooCommerce add fee to PayPal

When you choose ‘PayPal’ at the checkout, you’ll see an additional fee added to the totals:

WooCommerce additional fee for PayPal

How to apply a discount for certain payment gateways in WooCommerce

In this example, I’ll walk through applying a discount for customers who choose to pay via direct bank transfer. For the sake of the example, the discount will be calculated as a percentage of the overall order total.

  • Click on the ‘Direct bank transfer’ link
  • In ‘Label’ enter the text that you’d like to use to describe the discount
  • Choose ‘Percentage discount’ in the ‘Type’ dropdown
  • Enter the percentage in the ‘Amount’ field. In this example, we’ll give the customer a 1% discount for checking out via direct bank transfer.
  • Decide whether to include shipping costs in the cart total.
  • In ‘Minimum cart amount’, you can enter a minimum total for the cart before any charges are applied. In this example, we’ve set a minimum of 75 – meaning that the customer will need to spend 75 of whatever currency being used before they qualify for the discount
  • For ‘Maximum cart amount’, you can enter a maximum total for the cart above which no charges will be applied.
  • In ‘Minimum fee/discount amount’, you can enter a minimum value for the discount
  • For ‘Maximum fee/discount amount’, you can set a maximum value for the discount. In this example, we’ve limited the discount to 5
  • Check ‘Apply tax’ if you would like tax to be applied to the extra charge
  • Select the ‘Tax class’
  • Click ‘Save changes’
WooCommerce payment gateway discount

Now, when the user adds at least $75 worth of goods to the cart, they’ll qualify for 1% discount to a maximum of $5.

WooCommerce percentage based discount at checkout

Programmatically apply fees and discounts according to the payment gateway

If you prefer to create your own solution, here is some code to help with applying a fee at checkout based on payment gateway.

<?php
/**
* Add a fee when the user checks out with PayPal
*/
function wcfad_apply_payment_gateway_fee() {
$payment_method = WC()->session->get( 'chosen_payment_method' );
// Only apply the fee if the payment gateway is PayPal
// Note that you might need to check this slug, depending on the PayPal gateway you're using
if( $payment_method == 'ppec_paypal' ) {
$label = __( 'PayPal fee', 'wcfad' );
$amount = 5; // Change this value to whatever amount you wish
// Change the third parameter to false if you don't wish to apply tax to the fee
// Change the fourth parameter to a different tax class if required
WC()->cart->add_fee( $label, $amount, true, 'standard' );
}
}
add_action( 'woocommerce_cart_calculate_fees', 'wcfad_apply_payment_gateway_fee' );
/**
* Add some JS
*/
function wcfad_script() {
?>
<script>
jQuery(document).ready(function($){
$('body').on('change','.checkout .input-radio',function(){
$('body').trigger('update_checkout');
});
});
</script>
<?php
}
add_action( 'woocommerce_after_checkout_form', 'wcfad_script' );

This function gets the selected payment gateway for the user’s session and checks to see if it’s PayPal. Note that I’m using the ‘PayPal Checkout’ gateway rather than the older, standard ‘PayPal’ checkout.

If the user has selected the payment gateway, use WC()->cart->add_fee to add the fee. There are four parameters: label, amount, is_taxable, tax_class.

Finally, the function is hooked to woocommerce_cart_calculate_fees so it runs whenever the cart calculates fees.

Now, we just need a small piece of JavaScript to detect when the payment gateway is changed by the user. This triggers the WooCommerce update_checkout event which, in turn, will re-trigger woocommerce_cart_calculate_fees.

Wrapping up

I hope this has been helpful in demonstrating a couple of different ways to add fees or discounts to the WooCommerce checkout. Any questions, please leave a comment. You can find out more about the WooCommerce Fees and Discounts here.


Popular Posts

4 thoughts on “WooCommerce payment gateway based fees and discounts

How to know the slug used by payment method?

Reply

You can use WC()->payment_gateways->get_available_payment_gateways() to get a list of all payment gateways.

Reply

I use the PayU payment gateway that works in Latin America. PayU allows you to pay with credit cards (Visa, Mastercard and Amex) and also debit card.
I only wish to apply discount when selecting pay with Mastercard.
Is this possible?

Reply

Hi Eduardo

The Fees and Discounts plugin doesn’t differentiate between the credit card used, only between the payment gateway.

Reply

Leave a Reply

Your email address will not be published. Required fields are marked *