Skip to content
Advertisement

Assign a percentage fee to WooCommerce payment methods based on user roles

How do I expand this snippet to include 2 more payment gateways with different fees?

The payment gateways I want to add are ‘cardgategiropay’ and ‘cardgateideal’ and the fees are 3% and 2% respectively .

JavaScript

This code works fine. Just checking if my syntax is correct.

JavaScript

Advertisement

Answer

You could also array_intersect() to check user roles, use IF / ELSE statements, instead of only multiple IF statements and optimize and compact the code as follows:

JavaScript

Also something is missing to allow refresh checkout on payment gateway change:

JavaScript

Code goes in functions.php file of the active child theme (or active theme). Tested and works.


Related: Add fee based on specific payment methods in WooCommerce

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement