I started to work on small Woocommerce project. I have 3 payment gateways into this store: Paypal, Credit Card and Direct bank Transfer.
What I would like is: If coupon code is used, I would like to disable (or remove) Paypal and Credit Card from available payment gateways, and just keep "Direct bank Transfer" as available payment gateway choice.
To show how is look current state from checkout page:
I found a similar solution, but this is for removing gateway based on product category.
add_filter( 'woocommerce_available_payment_gateways', 'unset_payment_gateways_by_category' );
function unset_payment_gateways_by_category( $available_gateways ) {
global $woocommerce;
$unset = false;
$category_ids = array( 8, 37 );
foreach ( $woocommerce->cart->cart_contents as $key => $values ) {
$terms = get_the_terms( $values['product_id'], 'product_cat' );
foreach ( $terms as $term ) {
if ( in_array( $term->term_id, $category_ids ) ) {
$unset = true;
break;
}
}
}
if ( $unset == true )
unset( $available_gateways['cheque'] );
return $available_gateways;
}
So I think that this function can be used, but slightly modified per my problem.
Any help is appreciated.