Skip to content

Instantly share code, notes, and snippets.

@cristacheda
Created February 26, 2025 09:30
Show Gist options
  • Save cristacheda/079428508742bb1d32d8710d43b7db1e to your computer and use it in GitHub Desktop.
Save cristacheda/079428508742bb1d32d8710d43b7db1e to your computer and use it in GitHub Desktop.
WooCommerce extra fee for cash on delivery cod payment
<?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