Cash on delivery fee (αντικαταβολή)
Adds a fee to the order when the customer pays cash on delivery. The checkout totals update as soon as they pick it.
Fill in your details first. Set your fee in $fee (before VAT).
<?php
// The fee before VAT (WooCommerce adds VAT to fees): with 24% VAT, 1.61
// becomes 2.00. Change the label if you like.
$fee = 1.61;
$label = 'Έξοδα αντικαταβολής';
add_action(
'woocommerce_cart_calculate_fees',
static function ( $cart ) use ( $fee, $label ) {
if ( is_admin() && ! wp_doing_ajax() ) {
return;
}
if ( 'cod' === WC()->session?->get( 'chosen_payment_method' ) ) {
$cart->add_fee( $label, $fee, true );
}
}
);
// Recalculate the totals when the customer picks another payment method.
add_action(
'wp_footer',
static function () {
if ( function_exists( 'is_checkout' ) && is_checkout() && ! is_order_received_page() ) {
echo "<script>jQuery( function ( $ ) { $( 'form.checkout' ).on( 'change', 'input[name=\"payment_method\"]', function () { $( document.body ).trigger( 'update_checkout' ); } ); } );</script>";
}
}
);
Good to know
For the classic checkout.
In these packs
- Greek e-shop: For shops in Greece: receipt or invoice with a checked VAT number (ΑΦΜ), Greek phone and postcode checks, a cash on delivery fee, and greeklish addresses.