Skip to content

Instantly share code, notes, and snippets.

@amirulasyraf88
Created March 5, 2021 03:24
Show Gist options
  • Save amirulasyraf88/56d0f993cbdfa10c6edeaf1169efdbda to your computer and use it in GitHub Desktop.
Save amirulasyraf88/56d0f993cbdfa10c6edeaf1169efdbda to your computer and use it in GitHub Desktop.
Payment Fee
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