Last active
November 13, 2020 09:57
-
-
Save jeffreyvr/c2f70efb6a7d37061e73582265844715 to your computer and use it in GitHub Desktop.
Disable WooCommerce Mollie payment gateway for pickup shipping
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 | |
/** | |
* There seems to be no option to disable the Mollie gateway based | |
* on the selected shipping method. This filter removes | |
* Mollie when the shipping method contains 'pickup'. | |
* | |
* @param array $available_gateways The available gateways. | |
* | |
* @return array | |
*/ | |
function prefix_unset_mollie_for_pickup( $available_gateways ) { | |
if ( is_admin() ) { | |
return $available_gateways; | |
} | |
if ( ! is_checkout() ) { | |
return $available_gateways; | |
} | |
foreach ( WC()->session->get( 'chosen_shipping_methods' ) as $shipping_method ) { | |
if ( strpos( $shipping_method, 'pickup' ) !== false ) { | |
foreach ( $available_gateways as $gateway => $gateway_details ) { | |
if ( strpos( $gateway, 'mollie_wc_' ) !== false ) { | |
unset( $available_gateways[ $gateway ] ); | |
} | |
} | |
} | |
} | |
return $available_gateways; | |
} | |
add_filter( 'woocommerce_available_payment_gateways', 'prefix_unset_mollie_for_pickup' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment