Disable a Payment Method Above an Order Total
Hides a payment method such as cash on delivery or bank transfer when the order total goes above a limit you choose.
Opens WPIDE on
Code
add_filter( 'woocommerce_available_payment_gateways', function ( $gateways ) {
$gateway = 'cod'; // Payment method ID.
$max_total = 500; // Hide it above this order total.
if ( is_admin() || ! WC()->cart || ! isset( $gateways[ $gateway ] ) ) {
return $gateways;
}
if ( (float) WC()->cart->get_total( 'edit' ) > $max_total ) {
unset( $gateways[ $gateway ] );
}
return $gateways;
} );
Notes
Set $gateway and $max_total. The check uses the cart total including shipping and tax.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.