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’.
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:
Use this filter to ignore all role-based payment gateway rules for non-logged-in users
Use this filter to include non-logged-in users in ‘Permitted’ payment gateway rules
Use this filter to exclude non-logged-in users from ‘Restricted’ payment gateway rules
|* 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' );|
Here’s how to add a snippet.