Skip to content

Instantly share code, notes, and snippets.

@jeffreyvr
Last active November 13, 2020 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffreyvr/c2f70efb6a7d37061e73582265844715 to your computer and use it in GitHub Desktop.
Save jeffreyvr/c2f70efb6a7d37061e73582265844715 to your computer and use it in GitHub Desktop.
Disable WooCommerce Mollie payment gateway for pickup shipping
<?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