This is a cool function you can apply to any payment gateways for any order threshold. for example, you may want to disable bank transfers if orders are below $10, or disable PayPal payments if orders are above a certain cart total. Here’s what I did.
PHP Snippet: Disable PayPal payment gateway on WooCommerce orders above $100
/** * @snippet Disable PayPal Based on Cart Total - WooCommerce * @how-to businessbloomer.com/woocommerce-customization * @sourcecode https://businessbloomer.com/?p=377 * @author Rodolfo Melogli, Business Bloomer * @testedwith WooCommerce 3.5.6 * @community https://businessbloomer.com/club/ */ add_filter( 'woocommerce_available_payment_gateways', 'bbloomer_disable_paypal_above_100' ); function bbloomer_disable_paypal_above_100( $available_gateways ) { $maximum = 100; if ( WC()->cart->total > $maximum ) { unset( $available_gateways['paypal'] ); } return $available_gateways; }
Is There a WooCommerce “Payment Gateways by Cart Total” Plugin?
If you don’t feel 100% confident with coding, 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 π
Hmm, not sure this is still working. I’m using WP 5.9 and PHP 8.0 and it doesn’t appear to.
Screenshot of the checkout please?
Unfortunately this does not work for the Klarna plugin! Any idea why?
Thanks!
Probably it needs customization
HI, thank you.
I’m trying to disable “bacs” payment lower 100β¬.
I tried to modify:
– changed “maximum” > to “minimum”
– changed “paypal” > to “bacs”
But doesn’t works π
nevermind, i fix. thank you the same
Cool!
changing payment gateway to ‘paypal_express’ removes it as a gateway option, but it doesn’t disable the express checkout buttons.
Hi Asim, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi, thanks for the tutorials, very much helpful. We used this one as well, but we need one more thing which is slightly like this. Actually we have local delievery only, so we have minimum order amount for specific postcodes. And we have coded to throw custom error message at checkout page when a user try to click place order button with less amount than the minimum order amount for his postcode. This works fine for us for cod payments. But when it comes to Paypal Express checkout, the Paypal login modal opens before the validation. So the custom error message is not displaying, only the red alert mark is appearing.
I am using “woocommerce_checkout_process” hook to display wc notice errors.
Tom, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hello Rodolfo,
I’m using this function for disabling COD gateway. It works great, thanks! But is there a way to “grey out” payment method instead of hiding it completely? This way we can show our customers that they can stil use this payment method if they decrease their cart total.
Hi Deniz, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hey Rodolfo, Thanks for the amazing snippet. I would like to know If I change it from Paypal to COD and $100 to 10,000 rupees. Will it work? I have added the code below for your reference.
.
I have tested it with COD on staging and it worked. Great.
Awesome!
So great ! Every time I am looking for a function on google I find your website ! Thanks again.
Awesome!
Thank you for this! I’m trying to do something very similar, with product weight. I’d like the PayPal Gateway to be disabled on individual product pages (single product checkout) AND on the checkout page for all products that weigh 150lbs and over.
Is it possible for me to slightly tweak this code for that to happen?
I appreciate it!
Rob
Hello Rob, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R
Hi, great code.
I want to use it on the “pay_for_order” page also.
Can it be modified so it can be used also there π
(there is no cart total then)
Thanks Paul
Hello Paul, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R
Hi,
Since I changed from the standard paypal gateway to the WooCommerce PayPal Express Checkout Gateway this snippets is not working anymore. Any Idea how to fix it?
Thank you.
Hello Federico, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R
It works like a charm
Brilliant π
Thank you very much for sharing this.
You’re very welcome Raul!
How would you modify the code above to disable paypal express checkout? This is super awesome if I knew that.
Thanks for any help.
Hey Stephen, thanks for your comment! I suppose it depends on the plugin you’re using – which one is it? π