Skip to content

Instantly share code, notes, and snippets.

@rwkyyy
Last active December 2, 2020 16:09
Show Gist options
  • Save rwkyyy/c55245ccc1a9bba8f02043b5e3736a73 to your computer and use it in GitHub Desktop.
Save rwkyyy/c55245ccc1a9bba8f02043b5e3736a73 to your computer and use it in GitHub Desktop.
restrict payment gateway based on coupon code
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