How to Charge a Surcharge for Using Specific Payment Gateways in WooCommerce @ WordPress Help

How to Charge a Surcharge for Using Specific Payment Gateways in WooCommerce @ WordPress Help


While I know this is a bit of a controversial topic, from a legal perspective we are here to inform, and then you decide what to do with that information, do you think?

Well, this introduction is why today I want to share with you How to apply a surcharge, fee, commission or whatever you want to call it additional to your customers if they decide to pay with a specific payment gateway, for example PayPal (I don’t know, it just came to me suddenly, it wasn’t premeditated or anything… and stuff like that, and also PayPal says they don’t like you doing that).

And there it is payment gateways that charge very high fees for each transaction and penalize your profits on salescompared to other payment methods.

Of course, you can always do without payment gateways with abusive transaction costs and use the more moderate RedSys or Stripe, but you can’t always not offer your customers certain payment methods.

But I don’t get involved in the chaos anymore…

How to apply a surcharge for using a specific payment method (code)

Let’s start with the easy and effective one, a simple code with which to apply an additional cost to purchases if the customer uses that payment gateway. It would be like this:

/* Recargo si el cliente usa ESA pasarela de pago */
add_action( 'woocommerce_cart_calculate_fees', 'ayudawp_recargo_paypal' );
function ayudawp_recargo_paypal() {
$chosen_gateway = WC()->session->get( 'chosen_payment_method' );
if ( $chosen_gateway == 'paypal' ) {
WC()->cart->add_fee( 'Recargo PayPal', 4 );
}
}
add_action( 'woocommerce_after_checkout_form', 'ayudawp_reload_recargo_paypal' );
function ayudawp_reload_recargo_paypal(){
wc_enqueue_js( "
$( 'form.checkout' ).on( 'change', 'input[name^=\'payment_method\']', function() {
$('body').trigger('update_checkout');
});
");
}

In the code we are configuring that if the payment gateway chosen by the customer is PayPal (chosen_gateway) we apply a surcharge of 4%.

To apply the surcharge to another payment gateway, simply edit the file snail of the same, which you will find as I explained here.

For example, if I wanted to apply the surcharge to the bank transfer, due to the hassle of having to keep track of payments, and the manual work involved, the code would be like this:

/* Recargo si el cliente usa ESA OTRA pasarela de pago */
add_action( 'woocommerce_cart_calculate_fees', 'ayudawp_recargo_bacs' );
function ayudawp_recargo_bacs() {
$chosen_gateway = WC()->session->get( 'chosen_payment_method' );
if ( $chosen_gateway == 'bacs' ) {
WC()->cart->add_fee( 'Recargo transferencia bancaria', 5 );
}
}
add_action( 'woocommerce_after_checkout_form', 'ayudawp_reload_recargo_bacs' );
function ayudawp_reload_recargo_bacs(){
wc_enqueue_js( "
$( 'form.checkout' ).on( 'change', 'input[name^=\'payment_method\']', function() {
$('body').trigger('update_checkout');
});
");
}

In this case the surcharge we apply is 5%, it’s nothing.

How to apply a surcharge for using a specific payment method (plugin)

If you prefer to add another plugin to your internal WordPress arsenal, you can install this plugin to achieve the same result: Pay per payment – ​​To apply surcharges to most payment gateways (except Stripe).

Once installed, in the settings screen you will be able to specify the surcharge to apply to each of the payment gateways with which the plugin is compatible.

pay for woocommerce payment

As you can see, it has some settings to make automatic calculations based on the cart amount, taxes, shipping rates and coupons, in case you need to make some kind of discrimination in this regard.

That’s all, there’s nothing else. Don’t pay more, but watch your back!

Did you like this article? You can’t imagine what you’re missing a YouTube!



Source link

Related Posts

Leave a Reply

Open chat
Scan the code
Hello 👋
Can we help you?