Created
January 31, 2018 08:07
-
-
Save Roshanb54/8038a54380236c36f4479427a4031cd0 to your computer and use it in GitHub Desktop.
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
* Disable payment gateways for shipping methods | |
* Filter payment gatways | |
*/ | |
function my_custom_available_payment_gateways( $gateways ) { | |
$chosen_shipping_rates = WC()->session->get( 'chosen_shipping_methods' ); | |
// When 'local delivery' has been chosen as shipping rate | |
if ( in_array( 'local_delivery', $chosen_shipping_rates ) ) : | |
// Remove bank transfer payment gateway | |
unset( $gateways['bacs'] ); | |
endif; | |
return $gateways; | |
} | |
add_filter( 'woocommerce_available_payment_gateways', 'my_custom_available_payment_gateways' ); | |
* Enable payment gateways for shipping methods | |
* Filter payment gatways | |
*/ | |
function my_custom_available_payment_gateways( $gateways ) { | |
$chosen_shipping_rates = WC()->session->get( 'chosen_shipping_methods' ); | |
// When 'local delivery' has been chosen as shipping rate | |
if ( ! in_array( 'local_delivery', $chosen_shipping_rates ) ) : | |
// Remove bank transfer payment gateway | |
unset( $gateways['cod'] ); | |
endif; | |
return $gateways; | |
} | |
add_filter( 'woocommerce_available_payment_gateways', 'my_custom_available_payment_gateways' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment