Home » WooCommerce: Disable Payment Gateway For Specific Shipping Method

WooCommerce: Disable Payment Gateway For Specific Shipping Method

by Tutor Aspire

Today we take a look at the WooCommerce Checkout Page and specifically at how to disable a payment gateway (for example PayPal) when a specific shipping method is selected (e.g. “local_pickup”).

Specifically, you will learn how to “get” the selected shipping method on the go (thanks to “sessions”), and also how to “unset” a payment gateway. Enjoy!

WooCommerce: disable gateway based on shipping method
WooCommerce: disable gateway based on shipping method

PHP Snippet: Disable Payment Gateway For Specific Shipping Method – WooCommerce

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).

 * @snippet       Disable Payment Gateway For Specific Shipping Method
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @testedwith    WooCommerce 5
 * @donate $9     https://tutoraspire.com
add_filter( 'woocommerce_available_payment_gateways', 'tutoraspire_gateway_disable_for_shipping_rate' );
function tutoraspire_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;

Business Bloomer Premium Snippet®: WooCommerce Disable Payments By Shipping

You don’t feel confident with coding? Check.

You need more control over multiple payment/shipping rates exclusions? Check.

You don’t want to purchase yet another bloated, expensive plugin? Check.

Business Bloomer’s WooCommerce Disable Payments By Shipping Premium Snippet® is a mini WooCommerce plugin, without the usual hassles. Lifetime license. Just a few lines of code. Use it on as many websites as you like. Get lifetime support and documentation. A single and super-easy admin dashboard. Download as a plugin, as a Code Snippet or as raw PHP code.

Screenshot? Here you go:

As you can see Business Bloomer’s WooCommerce Disable Payments By Shipping Premium Snippet® settings are pretty straight forward. Select a payment method you wish to hide from the left, and the shipping rate that should trigger that from the right. Add more rules if needed. Simple!


WooCommerce Disable Payments By Shipping – Premium Snippet®

Lifetime license, lifetime support, lifetime updates

Download as plugin, Code Snippet or raw code

Use on unlimited websites

30 days 100% money-back guarantee

FAQ & Documentation

What does this Premium Snippet® do? Where do I find the settings?

It adds a new table under WooCommerce > Settings > Payments where you can define which payment method gets disabled at Checkout if a certain shipping rate is selected.

What’s the difference between the plugin, Code Snippet and raw code versions?

There is no difference, code is the exact same. And you will get access to all of them, so that you can pick whatever version suits you best. Want to use it as a plugin? Install it as a normal plugin via the supplied ZIP. Prefer using Code Snippets plugin? Cool, simply import the provided JSON snippet! Familiar with code? Great, easily place the raw code into your child theme’s functions.php file. Just pick one 🙂

Where can I get lifetime support?

On this same page. Simply click here to scroll down to the comments area. If you use the same email under your customer account, your comment will receive priority.

Where can I download my files?

Just head over to the My Account > My Downloads page. Here’s a direct link

What if a new version is released? How will I know?

As long as you don’t unsubscribe from Business Bloomer email list, you will receive an email once a new update is available. You can then go to the Downloads page and find the latest version.

I don’t see any payment gateway in the drodpown?

This happens if you have no payment gateway enabled. Enable one payment method and save changes before testing again.

I’ve tried the snippet but it doesn’t suit my needs. Can I return it?

Sure, and you get 100% money back if you request a refund within 30 days from your purchase. As of now there is no automated system on the My Account > My Orders page, so drop me an email and I’ll process your refund. Working on it though (expect an article on BB soon!)

Which payment gateways is this compatible with?

ALL payment gateways that show in the default Order Review area @ WooCommerce checkout (so PayPal, Stripe, etc.).

I have a pre-sale / post-sale question?

Cool! Post your request now and I’ll do my best to get back to you asap

Is There a More Advanced WooCommerce “Payment Gateways by Shipping Method” Plugin?

If you require a more advanced premium plugin, I decided to look for a reliable plugin that achieves the same result of this snippet (and more).

In this case, I found the WooCommerce Conditional Payment Gateways plugin to be the most complete when you need to enable/disable payment gateways based on certain criteria. You can create unlimited “rules” and use, for example, cart totals, billing country, shipping country, user role and much more to define which payment gateway shows and which not.

But in case you don’t want to use plugins and wish to code (or wish to try that), then keep reading 🙂

You may also like