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
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible.

Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

By using our site, you acknowledge that you have read and understood our Privacy Policy and Terms & Conditions.