Menu Close

Disable Payment Gateway For Specific Shipping Method


Let’s see how to disable a payment gateway (for example PayPal) when a specific shipping method is selected (e.g. “local_pickup”) in woocommerce checkout page.

In this example, I will disable “COD” payment gateway for all “local pickup” shipping rates in whatever shipping zone. You can also target a specific shipping rate (in a single zone).

Disable Payment Gateway For Specific Shipping Method – WooCommerce Checkout
add_filter( 'woocommerce_available_payment_gateways', codeamend_gateway_disable_for_shipping_rate);
function codeamend_gateway_disable_for_shipping_rate( $available_gateways ) {
   if ( ! is_admin() ) {
      $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
      $chosen_shipping = $chosen_methods[0];
      if ( isset( $available_gateways['cod'] ) && 0 === strpos( $chosen_shipping, 'local_pickup' ) ) {
         unset( $available_gateways['cod'] );
   return $available_gateways;
Note to find payment gateway slug: When you hover the payment gateway name in Woocommerce payment settings you can find refer:


Posted in WooCommerce

You can also read...

Leave a Reply

Your email address will not be published.