Skip to content

Instantly share code, notes, and snippets.

@gregogalante
Last active August 11, 2020 00:19
Show Gist options
  • Save gregogalante/aa1702ad00cb4c9eacda22e33da1bd05 to your computer and use it in GitHub Desktop.
Save gregogalante/aa1702ad00cb4c9eacda22e33da1bd05 to your computer and use it in GitHub Desktop.
Set conditional payments method based on shipping method select by the user.
<?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