Last active
August 11, 2020 00:19
-
-
Save gregogalante/aa1702ad00cb4c9eacda22e33da1bd05 to your computer and use it in GitHub Desktop.
Set conditional payments method based on shipping method select by the user.
This file contains 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 | |
// Hide payment gateways based on shipping method | |
function payment_gateway_disable( $available_gateways ) { | |
global $woocommerce; | |
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' ); | |
$chosen_shipping = $chosen_methods[0]; | |
if( $chosen_shipping == 1479475819 ) { | |
unset($available_gateways['cod']); | |
} | |
return $available_gateways; | |
} | |
add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment