Skip to content

Instantly share code, notes, and snippets.

@prionkor
Last active June 29, 2022 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prionkor/7e17472c4ccdf8fa2d026a390c765d66 to your computer and use it in GitHub Desktop.
Save prionkor/7e17472c4ccdf8fa2d026a390c765d66 to your computer and use it in GitHub Desktop.
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, '' );
}
}
@prionkor
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment