Instantly share code, notes, and snippets.

What would you like to do?
Add a charge to WooCommerce when the customer checks out via PayPal
* Add a fee when the user checks out with PayPal
function wcfad_apply_payment_gateway_fee() {
$payment_method = WC()->session->get( 'chosen_payment_method' );
// Only apply the fee if the payment gateway is PayPal
// Note that you might need to check this slug, depending on the PayPal gateway you're using
if( $payment_method == 'ppec_paypal' ) {
$label = __( 'PayPal fee', 'wcfad' );
$amount = 5; // Change this value to whatever amount you wish
// Change the third parameter to false if you don't wish to apply tax to the fee
// Change the fourth parameter to a different tax class if required
WC()->cart->add_fee( $label, $amount, true, 'standard' );
add_action( 'woocommerce_cart_calculate_fees', 'wcfad_apply_payment_gateway_fee' );
* Add some JS
function wcfad_script() {
$('body').on('change','.checkout .input-radio',function(){
add_action( 'woocommerce_after_checkout_form', 'wcfad_script' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment