mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-29 11:32:21 +08:00
28 lines
1,021 B
Text
28 lines
1,021 B
Text
function wc_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', 'wc_apply_payment_gateway_fee' );
|
|
/**
|
|
* Add some JS
|
|
*/
|
|
function wc_script() {
|
|
?>
|
|
<script>
|
|
jQuery(document).ready(function($){
|
|
$('body').on('change','.checkout .input-radio',function(){
|
|
$('body').trigger('update_checkout');
|
|
});
|
|
});
|
|
</script>
|
|
<?php
|
|
}
|
|
add_action( 'woocommerce_after_checkout_form', 'wc_script' );
|