• Plugins
  • Support
  • Blog
  • About
  • FAQ
Menu
  • Plugins
  • Support
  • Blog
  • About
  • FAQ
$0.00 0 Cart

How to Add Payment Method Fee in WooCommerce

  • August 9, 2021
  • -
  • Lauri / WP Trio

Some payment methods such as Cash on Delivery can be costly to the merchant. They incur additional fees or require extra labor. Easy but not the best solution would be to disable these costly payment methods altogether. However, some customers are accustomed to certain payment methods and if they are not available, they won’t order or order from elsewhere.

One way to encourage customers to use more convenient payment methods is to add additional fees to certain methods. Even if the customer should still select the costly method, the fee will bring additional revenue and offset costs to the merchant.

Fortunately it’s relatively easy to add payment method fees in WooCommerce. Below you will find a code snippet which will add $ 5 to the Direct bank transfer (BACS) method.

The easiest way to add the snippet is Code Snippets. Alternatively, it can be added to theme’s functions.php file.

<?php
/**
 * Add fee to bank transfer payment method
 */
add_action( 'woocommerce_cart_calculate_fees', function() {
	if ( is_admin() ) {
		return;
	}

	$payment_method = WC()->session->get( 'chosen_payment_method' );

	// Change bacs to another payment method ID where necessary
	if ( $payment_method === 'bacs' ) {
		$amount = 5; // How much the fee should be
		$tax = ''; // empty value equals to Standard tax rate
		$title = 'Bank transfer surcharge';
	
		WC()->cart->add_fee( $title, floatval( $amount ), true, $tax );
	}
}, 10, 0 );

/**
 * By default WooCommerce doesn't update checkout when changing payment
 * method so we need to trigger update here
 */
add_action( 'wp_head', function() {
?>
	<script type="text/javascript">
		jQuery(document).ready(function($) {
			/**
			 * Trigger checkout update when changing payment method
			 */
			$( document.body ).on( 'change', 'input[name="payment_method"]', function() {
				$( document.body ).trigger( 'update_checkout' );
			} );
		});
	</script>
<?php
}, 10, 0 );

After adding the snippet you should have $ 5 fee for Bank transfer like this:

How to find payment method IDs?

You will need to know the payment method ID before adding a fee to a certain payment method. The easiest way to find the ID is to head to WooCommerce > Settings > Payments and click on the payment method. The payment method ID should appear in the URL after section:

Add payment method fee with a plugin

If you would like to add the fee with a plugin or need additional conditionality such as fee per product category, Conditional Payments Pro is a great option. You can add fees to multiple payment methods and have conditions such as shipping class, product category, customer role and much more.

Check out Conditional Payments Pro »

Add fees easily with Conditional Payments Pro

Latest Posts

How Stock Sync Pro Keeps Your Stock in Check
Product Sync vs. Stock Sync: Understanding the Differences
How to Add Payment Method Fee in WooCommerce
Version 2 of Stock Sync – Migration Guide
How to Display “Add $ X to cart and get free shipping” on Checkout

Plugins

WooCommerce Conditional Payments Pro
WooCommerce Conditional Shipping Pro
WooCommerce Product Sync Pro
WooCommerce Stock Sync Pro
30 DAY MONEY BACK GUARANTEE
+6000 HAPPY CUSTOMERS
SUPPORT FROM THE DEVELOPER

WP Trio / BitBot Oy
Flätbackantie 1, 04150 Sipoo
FINLAND
VAT ID: FI28269925

WP Trio

  • Support
  • Blog
  • About
  • FAQ
  • My account
  • Support
  • Blog
  • About
  • FAQ
  • My account

Plugins

  • Plugins
  • Docs
  • Plugins
  • Docs