In this tutorial, we will show you how to disable WooCommerce payment methods when the customer buys products from multiple categories.
For example, you can have PayPal activated when the customer buys a product from the Fashion category, but automatically deactivate it when the customer adds products from the Fashion and Technology categories. In other words, users will only be able to buy from one category; otherwise, the selected payment method will be automatically deactivated.
For this, we will use the WooCommerce Conditional Payment Gateways plugin. This is a plugin that allows you to apply conditional restrictions to all your payment methods without having to program anything. We use conditional logic, but we have simplified it as much as possible so that you can easily manage your payment methods.
You can download the plugin here:
Download WooCommerce Conditional Payment Gateways Plugin - or - Read more
After installing and activating the plugin on your WordPress site, you need to follow these really easy steps to disable payment methods when customers purchase products from multiple categories.
1- Open the WooCommerce Conditional Payment Gateways plugin
The first thing you need to do to disable payment gateways when users purchase products from several categories is to open the WooCommerce Conditional Payment Gateways plugin options.
You can easily do it by going to WooCommerce > Conditional Payment Methods.
2- Add a new condition to your payment gateways
Normally, if you want to restrict your WooCommerce payment gateways based on cart details, checkout details, product details, or by user details, dates and times, you would have to program the conditions from scratch. But our plugin allows you to easily enable or disable payment methods with a few clicks.
You can create a new condition for your payment gateways by clicking Add Condition.
3- Disable payment gateways when buying from multiple categories
We will now create a new condition for our selected payment methods that states that, in order to use the selected payment method, customers must purchase products from a single category. If the cart includes products from two or more categories, the payment method will be automatically disabled.
For example, we will restrict the PayPal payment method if the customer buys from two or more categories.
Just select these values:
- Add new condition: Enter the new condition title.
- What happens when the conditions are met: Disable payment method(s)
- Select the payment methods: We’ll select PayPal in this example.
- Condition 1: Buying from multiple categories = Yes
- Finally, Publish the condition.
Once you publish this new condition for your payment gateways, customers will be able to pay for their products on your store only when they buy from a single category. If their order includes products from two categories, the payment method will be disabled automatically.
Payment method disabled when customers buy from multiple categories
As you can see in the screenshot below, we have products from two categories in our WooCommerce store. Some products belong to the “Accessories” category; other products belong to the “tshirts” category.
Under the condition that we have just created, PayPal must be enabled when we buy from only one category and disabled when we buy from two categories.
And indeed, you can see that we have added a product from the “Accessories” category to our cart, and the PayPal payment method is enabled. This is because we’re only buying from one category.
On the other hand, if we add a new product from the “tshirts” category to our cart, you will see that the PayPal payment gateway will be automatically deactivated at checkout.
That was really easy!
As you can see, the restrictions from WooCommerce Conditional Payment Gateways work well to restrict your payment methods.
In this case, we have disabled a payment gateway when the user buys from multiple categories. But there are many other restriction methods that you can quickly enable.
You can visit our blog to find more tutorials on how to easily apply conditional restrictions to your payment methods in WooCommerce.
You can download the plugin here:
Download WooCommerce Conditional Payment Gateways Plugin - or - Read more