/** * Add a payment gateway surcharge to checkout */ // Part 1: assign fee add_action('woocommerce_cart_calculate_fees', 'cc_add_checkout_fee_for_gateway'); function cc_add_checkout_fee_for_gateway() { $chosen_gateway = WC()->session->get('chosen_payment_method'); $surcharge = 0.03; // Increase price by 3% $cart_total = WC()->cart->get_subtotal(); if ( $chosen_gateway == 'paypal' ) { WC()->cart->add_fee('PayPal Processing Fee', $cart_total * $surcharge); } if ( $chosen_gateway == 'eh_stripe_pay' ) { WC()->cart->add_fee('Stripe Processing Fee', $cart_total * $surcharge); } } // Part 2: reload checkout on payment gateway change add_action('woocommerce_review_order_before_payment', 'cc_refresh_checkout_on_payment_methods_change'); function cc_refresh_checkout_on_payment_methods_change() { ?>