Cash on delivery only up to €300
Cash on delivery disappears from the payment methods when the order total is above the amount you set.
Before you switch it on: Set $maximum to the highest order total you accept cash on delivery for.
It arrives switched off, even when you install its whole pack with "Switch on after installing".
<?php
add_filter(
'woocommerce_available_payment_gateways',
static function ( $gateways ) {
$maximum = 300;
if ( is_admin() || ! WC()->cart ) {
return $gateways;
}
if ( isset( $gateways['cod'] ) && (float) WC()->cart->get_total( 'edit' ) > $maximum ) {
unset( $gateways['cod'] );
}
return $gateways;
}
);
In these packs
- WooCommerce: cart and checkout: Free-shipping progress, coupon links, quantity limits and a cleaner checkout.