Skip to content
Advertisement

Add a custom fee for percentage and fixed cost to specific payment gateway in WooCommerce

In WooCommerce I need to apply a custom handling fee for a specific payment gateway.

A custom handling fee for percentage cost and a custom handling for per fixed cost.

I have this 2 pieces of codes:

A) PERCENTAGE COST – function

JavaScript

Result frontend

enter image description here


B) FIXED COST – function

JavaScript

Result frontend

enter image description here



The two distinct functions work perfectly separately. Now, I would like to combine the two functions to get the sum of the two costs.

My code attempt (A + B): function evolution with addition other payment systems

enter image description here

JavaScript

The function returns the following errors:

Notice: Undefined variable: surcharge in /MY-FOLDER…./snippet-ops.php(446) : eval()’d code on line 79

Notice: Undefined variable: fee in /MY FOLDER…./snippet-ops.php(446) : eval()’d code on line 79

That is exactly here:

JavaScript

Result frontend

enter image description here

Any advice on how to combine the 2 codes above into 1?

Advertisement

Answer

The difference between the 2 examples you’ve posted is really minimal. You can just use:

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