Skip to content

Instantly share code, notes, and snippets.

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 JeroenSormani/4115f614a43eeab8982c to your computer and use it in GitHub Desktop.
Save JeroenSormani/4115f614a43eeab8982c to your computer and use it in GitHub Desktop.
Disable payment gateways for shipping rates
<?php
/**
* 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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment