 
	
		
		
		
		
			
I am currently using the function below in my theme functions.php file to add a convenience fee to the entire cart, however, I would prefer to only add this fee to the credit card payment method only. I don’t see that setting in the payment plugin I am using (https://wordpress.org/plugins/woo-stripe-payment/). I have reached out to them as well.
Is there a way to modify the function below to apply the convenience fee only when the user selects a credit card as the payment method so it doesn’t apply to ACH payments?
add_action( ‘woocommerce_cart_calculate_fees’, ‘add_percentage_processing_fee’ );
function add_percentage_processing_fee() {
    if ( is_admin() && ! defined( ‘DOING_AJAX’ ) ) {
        return;
    }
    $percentage = 0.027; // 2.7% credit card processing fee
    $cart = WC()->cart;
    $cart_total = $cart->cart_contents_total;
    // Calculate the fee
    $processing_fee = $cart_total * $percentage;
    // Add the fee to the cart
    $cart->add_fee( __( ‘2.7% credit card processing fee’, ‘your-text-domain’ ), $processing_fee );
}
Hey jamesedwardcouncill,
I didn’t find anything in the official woocommerce API documentation Note that they only offer:
Add a percentage based surcharge to all transactions
Add a standard $ value surcharge to all transactions
Add a surcharge based on the delivery country
I also found this paid plugin that only offers the same options: Payment Gateway Based Fees
But I did find this snippet: Adding cart fees depending on the chosen payment gateway
I don’t have a way to test it, but perhaps it will work for you.
Best regards,
Mike
