Created
March 5, 2021 03:24
-
-
Save amirulasyraf88/56d0f993cbdfa10c6edeaf1169efdbda to your computer and use it in GitHub Desktop.
Payment Fee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'woocommerce_cart_calculate_fees', 'bbloomer_add_checkout_fee_for_gateway' ); | |
function bbloomer_add_checkout_fee_for_gateway() { | |
$chosen_gateway = WC()->session->get( 'chosen_payment_method' ); | |
if ( $chosen_gateway == 'hoolah_checkout' ) { | |
global $woocommerce; | |
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) | |
return; | |
$subtotal = $woocommerce->cart->subtotal; | |
$fee_percentage = 0.08; // 2.5% percent | |
$fee = number_format( round( $subtotal * $fee_percentage, 2 ), 2 ); // rounded to two decimal places to match currency formatting | |
$woocommerce->cart->add_fee( 'Processing Charges 8%', $fee, true, 'standard' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment