Skip to content

Instantly share code, notes, and snippets.

@goranefbl
Created September 11, 2025 11:07
Show Gist options
  • Save goranefbl/cd88130b53f76c6fbdf3783b1244af37 to your computer and use it in GitHub Desktop.
Save goranefbl/cd88130b53f76c6fbdf3783b1244af37 to your computer and use it in GitHub Desktop.
points and rewards - limit to roles
add_filter('wpgens_loyalty_update_points', 'filter_points_by_user_role', 5, 6);
function filter_points_by_user_role($user_id, $points_delta, $type, $source, $reference_id = null, $description = null) {
// Define roles that should be excluded from points system
$excluded_roles = ['wholesale_customer', 'restricted_user', 'employee'];
// Get user object
$user = get_userdata($user_id);
if (!$user) {
return false; // User not found
}
// Check if user has any excluded roles
$user_roles = (array) $user->roles;
$has_excluded_role = array_intersect($user_roles, $excluded_roles);
if (!empty($has_excluded_role)) {
WPGL_Logger::points("Points update blocked for excluded role", [
'user_id' => $user_id,
'user_roles' => $user_roles,
'excluded_roles' => $excluded_roles,
'points_delta' => $points_delta,
'source' => $source
]);
return false; // Block the points update
}
// Allow points update to continue
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment