Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Disable Payment Gateway For Specific Shipping Method in WooCommerce?

The code helps to customize the WooCommerce checkout page by dynamically disabling a certain payment gateway when a specific shipping method is chosen.

add_filter( 'woocommerce_available_payment_gateways', 'ts_gateway_disable_for_shipping_rate' );
  
function ts_gateway_disable_for_shipping_rate( $available_gateways ) {
   if ( ! is_admin() && WC()->session ) {
      $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;
}

Output

The code disables ‘Cash on Delivery’ when ‘local pickup’ is chosen as their preferred shipping method during checkout. Irrespective of any zone the particular payment gateway is disabled here.

How to Disable Payment Gateway For Specific Shipping Method in WooCommerce?

Disabling payment gateways can be done on various conditions. As done in the above criteria, you can also disable payment method for specific category WooCommerce checkout.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x