Created
January 5, 2026 15:50
-
-
Save goranefbl/f05080ae3b6669e5492e7a4f90dc7012 to your computer and use it in GitHub Desktop.
Redeem actions limit to certain ranks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_filter('wpgens_loyalty_get_redeem_actions', 'restrict_redeem_actions_by_rank', 10, 2); | |
| function restrict_redeem_actions_by_rank($redeem_actions, $user_id) { | |
| if (!$user_id || !class_exists('WPGL_Ranks_Core')) { | |
| return $redeem_actions; | |
| } | |
| // Define which rewards require which ranks | |
| // Use the redeem action ID (visible in admin) and rank slug or ID | |
| $rank_requirements = [ | |
| 'reward_id_1' => 'silver', // This reward requires Silver rank or higher | |
| 'reward_id_2' => 'gold', // This reward requires Gold rank or higher | |
| 'reward_id_3' => 'platinum', // This reward requires Platinum rank | |
| ]; | |
| return array_filter($redeem_actions, function($action) use ($user_id, $rank_requirements) { | |
| $action_id = (string) $action['id']; | |
| // If this reward has no rank requirement, show it | |
| if (!isset($rank_requirements[$action_id])) { | |
| return true; | |
| } | |
| // Check if user has achieved the required rank (or higher) | |
| return WPGL_Ranks_Core::check_user_rank($user_id, $rank_requirements[$action_id], true); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment