woocommerce disable payment method if coupon appied and total is 0

Solutions on MaxInterview for woocommerce disable payment method if coupon appied and total is 0 by the best coders in the world

showing results for - "woocommerce disable payment method if coupon appied and total is 0"
Stan
25 Jun 2018
1add_filter('woocommerce_available_payment_gateways', 'applied_coupons_hide_payment_gateways', 20, 1 );
2function applied_coupons_hide_payment_gateways( $available_gateways){
3    // Not in backend (admin)
4    if( is_admin() ) 
5        return $available_gateways;
6
7    // If at least a coupon is applied
8    if( sizeof( WC()->cart->get_applied_coupons() ) > 0 ){
9        // Loop through payment gateways
10        foreach ( $available_gateways as $gateway_id => $gateway ) {
11            // Remove all payment gateways except BACS (Bank Wire)
12            if( $gateway_id != 'bacs' )
13                unset($available_gateways[$gateway_id]);
14        }
15    }
16
17    return $available_gateways;
18}
19