Last active
June 29, 2022 20:30
-
-
Save prionkor/7e17472c4ccdf8fa2d026a390c765d66 to your computer and use it in GitHub Desktop.
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', 'prionkor_cod_fee' ); | |
function prionkor_cod_fee() { | |
global $woocommerce; | |
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; | |
// get your payment method | |
$fee = 10; | |
$chosen_gateway = WC()->session->chosen_payment_method; | |
if ( $chosen_gateway == 'cod' ) { //test with cash on delivery method | |
WC()->cart->add_fee( 'Cash on Delivery Fee', $fee, false, '' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Originally published here https://www.codesmade.com/woocommerce-cash-on-delivery-extra-fee-programmatically/