Hi @marcoslmdb,
Yes, it’s possible to set the Invoice Gateway to specific user. You can either set the payment method exclusive to user roles or user IDs. I’ll send you both snippet so that you can choose based on your needs ??
Don’t forget to change the values in $allowed_roles
array for restricting based on user roles, and $allowed_user_ids
for restricting based on user IDs.
Set Invoice Gateway payment method for specific roles
// Invoice payment gateway only available for specific roles
add_filter( 'woocommerce_available_payment_gateways', 'igfw_restrict_to_specific_roles' );
function igfw_restrict_to_specific_roles( $available_gateways ) {
$allowed_roles = array(
'role_1',
'role_2',
'role_3',
);
if ( ! is_user_logged_in() ) {
unset( $available_gateways['igfw_invoice_gateway'] );
} else {
$user = wp_get_current_user();
$user_roles = ( array ) $user->roles;
if ( empty( array_intersect( $allowed_roles, $user_roles ) ) ) {
unset( $available_gateways['igfw_invoice_gateway'] );
}
}
return $available_gateways;
}
Set Invoice Gateway payment method for specific user IDs
// Invoice payment gateway only available for specific user IDs
add_filter( 'woocommerce_available_payment_gateways', 'igfw_restrict_to_specific_user_ids' );
function igfw_restrict_to_specific_user_ids( $available_gateways ) {
$allowed_user_ids = array(
1,
2,
3,
);
if ( ! is_user_logged_in() ) {
unset( $available_gateways['igfw_invoice_gateway'] );
} else {
$user = wp_get_current_user();
$user_id = $user->ID;
if ( ! in_array( $user_id, $allowed_user_ids ) ) {
unset( $available_gateways['igfw_invoice_gateway'] );
}
}
return $available_gateways;
}