1. Home
  2. Knowledge Base
  3. WooCommerce Members Only
  4. Roles
  5. Restrict or allow payment gateways by user role
  1. Home
  2. Knowledge Base
  3. WooCommerce Members Only
  4. Restrict or allow payment gateways by user role

Restrict or allow payment gateways by user role

You can choose to restrict certain payment gateways to specific user roles. In WooCommerce > Settings > Members Only > Payment Methods, you’ll see a list of all the payment methods enabled on your site.

Under each payment method, there’s a field for ‘Restricted roles’ and a field for ‘Permitted roles’.

woocommerce payment methods

If you want to prevent users with specific roles from using a certain payment method, enter the roles in the ‘Restricted roles’ field.

If, on the other hand, you want to enable the payment method for certain roles, enter those roles in the ‘Permitted roles’ field.

Payment gateway filters for non-logged-in users

By default, payment gateway rules will always assume that non-logged-in users don’t have the correct role, whatever the rule.

You can apply one of the filters below to change this behaviour:

  • wcmo_ignore_payments_for_non_logged_in
    Use this filter to ignore all role-based payment gateway rules for non-logged-in users
  • wcmo_ignore_permitted_payments_for_non_logged_in
    Use this filter to include non-logged-in users in ‘Permitted’ payment gateway rules
  • wcmo_ignore_restricted_payments_for_non_logged_in
    Use this filter to exclude non-logged-in users from ‘Restricted’ payment gateway rules
<?php
/**
* Filters for role-based payment gateways
*/
// Use this filter to ignore all role-based payment gateway rules for non-logged-in users
add_filter( 'wcmo_ignore_payments_for_non_logged_in', '__return_true' );
// Use this filter to include non-logged-in users in 'Permitted' payment gateway rules
add_filter( 'wcmo_ignore_permitted_payments_for_non_logged_in', '__return_true' );
// Use this filter to exclude non-logged-in users from 'Restricted' payment gateway rules
add_filter( 'wcmo_ignore_restricted_payments_for_non_logged_in', '__return_true' );
view raw gistfile1.txt hosted with ❤ by GitHub

Here’s how to add a snippet.

Was this article helpful?

Related Articles