-
-
Save femiyb/e12fd5c4c9d3f6e5f1f1b78926b57c24 to your computer and use it in GitHub Desktop.
Give members a different level when expiring or cancelling based on their previous level.
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
| /* | |
| When users cancel (are changed to membership level 0) who previously belonged to | |
| level 2 are given level 1 with expiration date of one year. | |
| */ | |
| function my_pmpro_after_change_membership_level($level_id, $user_id) | |
| { | |
| $levelshistory = $wpdb->get_results("SELECT * FROM $wpdb->pmpro_memberships_users WHERE user_id = '$current_user->ID' ORDER BY id DESC"); | |
| if($levelshistory && $levelshistory[0]->membership_id == 2 && $level_id == 0) | |
| { | |
| //cancelling, give them level 1 instead | |
| $expiry_level_id = 1; | |
| $level = pmpro_getLevel($expiry_level_id); | |
| //give them an expiry date one year from today. | |
| $level->enddate = date('Y-m-d',strtotime(date("Y-m-d", mktime()) . " + 365 day")); | |
| pmpro_changeMembershipLevel($level, $user_id); | |
| } | |
| } | |
| add_action("pmpro_after_change_membership_level", "my_pmpro_after_change_membership_level", 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment