WooCommerce – Hide Payment Gateways Based on User Age

In this post, we show you how to hide payment gateways based on user age.

This can be very useful because sometimes, there are users who try to use payment methods that can be risky. For example, if a child orders something from your store with his or her parent’s credit card, the parent may ask for a refund because he or she did not approve the transaction, or when you sell products with legal restrictions like alcoholic beverages.

To find out the age of the customer in WooCommerce, you can use any plugin that allows you to add fields to the WooCommerce checkout. For example, the Checkout Manager for WooCommerce plugin. With this plugin, you can add a number field called “Age“.

Once you have added the age field to your WooCommerce Checkout, you need to 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 they won’t be able to complete the purchase.

We’ll do this really quickly with the Conditional Payment Gateways plugins.

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

Something great is that the plugin allows you to add several conditions, so you can select different ages for different countries.

1- Hide payment gateway based on user 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 payment gateway based on the 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 age under 21 by selecting this condition: Custom field: Age < 21
  • Click Publish.

hide payment gateway based on user age

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 user 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 in order 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.

hide payment gateway based on user age

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.

Conditional payment methods simplifies it for you!

Normally, you’d have to be skilled in programming to hide payment gateways based on user age. However, with Conditional Payment Gateways, you can select this any many other conditions to manage your payment gateways the way you want.