Last active
          December 2, 2020 16:09 
        
      - 
      
- 
        Save rwkyyy/c55245ccc1a9bba8f02043b5e3736a73 to your computer and use it in GitHub Desktop. 
    restrict payment gateway based on coupon code
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | add_filter( 'woocommerce_available_payment_gateways', 'conditional_available_payment_gateways' 20, 1 ); | |
| function conditional_available_payment_gateways( $available_gateways ) { | |
| if( is_admin() ) return $available_gateways; // Only for frontend admin | |
| $coupon_code ='cod'; | |
| if ( WC()->cart->has_discount( $coupon_code ) ) { | |
| unset( $available_gateways['cod'] ); | |
| } | |
| return $available_gateways; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment