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