Created
February 26, 2025 09:30
-
-
Save cristacheda/079428508742bb1d32d8710d43b7db1e to your computer and use it in GitHub Desktop.
WooCommerce extra fee for cash on delivery cod payment
This file contains hidden or 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
<?php | |
// A fee of 5 USD is charged for payment processing by the courier. | |
add_action( 'woocommerce_cart_calculate_fees', function() { | |
$cod_fee = 4.202; // no VAT value | |
$chosen_gateway = WC()->session->get( 'chosen_payment_method' ); | |
if ( $chosen_gateway == 'cod' ) { // 'cod' stands for Cash on Delivery | |
$chosen_shipping_methods = wc_get_chosen_shipping_method_ids(); | |
if ( !in_array('local_pickup', $chosen_shipping_methods) ) { | |
WC()->cart->add_fee( __('Cash Payment processing fee, online card payment is free.', 'woocommerce'), $cod_fee, true, '' ); | |
} | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment