Last active
July 21, 2021 09:06
-
-
Save dev-w3/2179c1e03434da13bf90d1a26a20eb24 to your computer and use it in GitHub Desktop.
To hide payment method if coupon is applied in woo-commerce
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
<?php | |
add_filter('woocommerce_available_payment_gateways', '_hide_payment_gateways', 20, 1 ); | |
function _hide_payment_gateways( $available_gateways){ | |
// Not in backend (admin) | |
if( is_admin() ) | |
return $available_gateways; | |
// If at least a coupon is applied | |
if( sizeof( WC()->cart->get_applied_coupons() ) > 0 ){ | |
// Loop through payment gateways | |
foreach ( $available_gateways as $gateway_id => $gateway ) { | |
//echo $gateway_id; | |
// Remove all payment gateways except BACS (Bank Wire) | |
if( $gateway_id != 'bacs' ) | |
unset($available_gateways[$gateway_id]); | |
// or you can simply pass any specific gateway id if you want to hide any specific | |
} | |
} | |
return $available_gateways; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hide specific payment method if coupon is applied in Woocommerce
Eg: if you want to use the coupon code for the Bank Wire method only.
Need to put this code in the functions.php in the theme