Let’s take a look at how to disable WooCommerce payment gateways from the checkout page based on customer age. Disabling payment methods based on customer or user age can be handy for different situations.
For example, stores receive refund requests alleging that a minor used a credit card to place an order. In cases like this, you can avoid liability by asking the user to enter their age on the checkout page. If the user is younger than the minimum age stipulated, the payment method(s) of your choice will be disabled.
Another useful case is to disable all payment gateways when the customer is a minor, especially when you sell products that should only be purchased by people of legal age.
To have the customers add their age on checkout, you can use any plugin to add fields to the WooCommerce checkout page/form.
For example, the Checkout Manager for WooCommerce plugin allows you to add an “Age” number field.
Once you have added the age field to your WooCommerce Checkout form, you must add a condition to your payment gateways to set a minimum age value.
If users are younger than the minimum age set, they won’t be able to use the payment methods and won’t be able to complete the purchase.
We’ll do this with the WooCommerce Conditional Payment Gateways plugin.
You can enable or disable payment gateways using any of these filters/conditions:
- Contains product
- Contains shipping class
- Coupon Discounts total
- Coupon
- Custom field
- Is order pay page?
- Quantity
- Shipping method
- Shipping total
- Subtotal exc. taxes
- Subtotal
- Tax
- Total
- Billing city
- Billing company
- Billing country
- Billing email
- Billing state
- Billing zipcode
- Customer email
- Days since registration date
- Previous orders from the customer
- Shipping city
- Shipping company
- Shipping Country
- Shipping state
- Shipping zipcode
- User role
- Is on backorder?
- Category
- Height
- Length
- Taxonomy: Product categories
- Taxonomy: Product tags
- Variation IDs
- Weight
- Width
- Date (YYYY-MM-DD)
- Hour of the day (number from 0 to 23)
- Day of the month (number from 1 to 31)
- Day of the week
You can download the plugin here: Download WooCommerce Conditional Payment Gateways Plugin - or - Read more
Something great is that the plugin allows you to add several conditions, so you can select different ages for different countries.
1- Disable WooCommerce payment gateway based on customer age
To hide payment gateways based on user age for all countries, go to WooCommerce > Conditional Payment Methods.
Once you’re there, click Add Condition.
You need to use these values on the new condition to hide the payment gateway based on age:
- Enter the condition title
- What happens when the conditions are met: Disable the payment method(s)
- Select the payment methods: Select the method you want to hide; for example, Stripe and Bank transfer.
- Conditions: For example, you can disable the selected payment gateway for ages under 21 by selecting this condition: Custom field: Age < 21
- Click Publish.
With this condition, all users under 21 years of age won’t see the selected payment method on WooCommerce checkout.
2- Hide payment gateway based on customer age and country
This option is great for countries that use a different minimum age.
For example, in Mexico, you must be at least 21 years old to make any legal arrangements or payments.
That’s different in other countries, so you may need to add more than one condition.
In this example, we’ll set 18 years for Mexico and 21 years for the United States.
You need to add these values:
- Enter the condition title
- What happens when the conditions are met: Disable the payment method(s)
- Select the payment methods: Select the method you want to hide; for example, Stripe and Bank transfer.
- To disable the selected payment gateway for users under 18 years in Mexico:
- Condition 1: Custom field: Age < 21
- Click + to add an “and” condition.
- Condition 2: Billing country = Mexico
- Click Add ‘Or’ condition.
- To disable the selected payment gateway for users under 21 years in the United States:
- Condition 1: Custom field: Age < 21
- Click + to add an “and” condition.
- Condition 2: Billing country = United States (US)
- Click Publish.
After setting these values, customers from Mexico will need to be at least 18 years old to use the selected payment gateway.
On the other hand, customers from the United States will need to be at least 21 years old to use the selected payment method.
Normally, you’d have to be skilled in programming to hide payment gateways based on user age.
However, with WooCommerce Conditional Payment Gateways, you can select this and many other conditions to manage your payment gateways the way you want.
You can download the plugin here: Download WooCommerce Conditional Payment Gateways Plugin - or - Read more