Skip to content

Instantly share code, notes, and snippets.

@amirulasyraf88
Created July 23, 2020 07:49
Show Gist options
  • Save amirulasyraf88/8823d494cb3338f59e413f3a27ab83be to your computer and use it in GitHub Desktop.
Save amirulasyraf88/8823d494cb3338f59e413f3a27ab83be to your computer and use it in GitHub Desktop.
Payment Processing Fee
<?php
//Payment Gateway Selection
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 == 'paypal' ) {
WC()->cart->add_fee( 'PayPal Fee', 5 );
}
}
// Part 2: reload checkout on payment gateway change
add_action( 'woocommerce_review_order_before_payment', 'bbloomer_refresh_checkout_on_payment_methods_change' );
function bbloomer_refresh_checkout_on_payment_methods_change(){
?>
<script type="text/javascript">
(function($){
$( 'form.checkout' ).on( 'change', 'input[name^="payment_method"]', function() {
$('body').trigger('update_checkout');
});
})(jQuery);
</script>
<?php
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment