Simple Membership Plugin › Forums › Simple Membership Plugin › Downgrade account instead of expire?
Tagged: downgrade membership, roles
- This topic has 9 replies, 3 voices, and was last updated 8 years, 3 months ago by
E-Artisan.
-
AuthorPosts
-
January 20, 2018 at 1:47 am #13048
Daniel
ParticipantI have 2 paid memberships, Silver and Gold. Silver expires after 1 year. Gold expires after 1 month. When a user pays for the Silver membership, at anytime they can upgrade to Gold. You can not directly become Gold without purchasing Silver first.
Is it possible to “auto downgrade” a Gold membership to Silver after the 1 month? Then continue with their Silver privileges?
Right now, after Gold is finished, it’s account status becomes expired and they loose access to their already purchased Silver privileges.Manually changing the account status is not a desired option due to the number of members.
(By the way, I’m very comfortable hard coding PHP if necessary)
Thanks
January 20, 2018 at 5:10 am #13049mbrsolution
ModeratorHi, there is another option you could try. Have you enabled the following option Enable Expired Account Login under Advance Settings? This would allow your members to log back in and renew their membership account.
Would this work for you?
Regards
January 22, 2018 at 5:23 pm #13078Daniel
ParticipantUnfortunately this wouldn’t work. Upgrading to Gold is meant to be a short term upgrade (about a month) from Silver. Right now having an expired Gold also expires their Silver membership which is meant to last the rest of the year.
Any other ideas?
January 22, 2018 at 8:45 pm #13079mbrsolution
ModeratorHi, please read the following documentation. Let me know if this would help you in any way?
Thank you
January 22, 2018 at 11:38 pm #13083Daniel
ParticipantI had to add custom code to my functions.php page but I was able to achieve what I wanted. Thank you for your help. Not sure if I should post the code or not. Let me know if that’s okay.
Thanks!
January 22, 2018 at 11:48 pm #13085mbrsolution
ModeratorI am happy to hear that you manage to fix your issue. You can share your code if you like. This would help others trying to achieve the same as you.
Kind regards
January 23, 2018 at 12:27 am #13087Daniel
ParticipantI put this in my current theme’s functions.php file.
// Simple membership - auto downgrade membership type of Gold to membership type of Silver on membership expiry function auto_downgrade_membership_type(){ // Is a user logged in? if(SwpmMemberUtils::is_member_logged_in() == true){ // Yes. A user is logged in. // Get the user's member id. We will use this later.* $mId = SwpmMemberUtils::get_logged_in_members_id(); // Get the user's current membership account state. We will use this later.** $auth = SwpmAuth::get_instance(); $account_state = $auth->get('account_state'); // Is their current membership level Gold? if(SwpmMemberUtils::get_logged_in_members_level_name() == "Gold"){ // Yes. The user's membership type is Gold. // Is their Gold Membership expired? if(SwpmUtils::is_subscription_expired($user) == true){ // Yes. The user's Gold membership has expired. // Downgrade the Gold membership to Silver membership - using the user's id variable above* and the id of the desired membership level. SwpmMemberUtils::update_membership_level($mId, 2); // Change the new membership (Silver) account state to "active" because the membership (Gold) account state still thinks it's expired. SwpmMemberUtils::update_account_state($mId, $new_status = 'active'); // If an admin manually changed a member's account state to expired (for some reason...) but the membership expire date hasn't been reached. // Check the user's current membership account state.** }elseif($account_state == 'expired'){ // Downgrade the Gold membership to Silver membership type - using the user's id variable above* and the id of the desired membership level. SwpmMemberUtils::update_membership_level($mId, 2); // Change the new membership (Silver) account state to "active" because the membership (Gold) account state still thinks it's expired. SwpmMemberUtils::update_account_state($mId, $new_status = 'active'); }else{ // No. The user still has Gold privileges. } }else{ // No. The user's current membership type is Silver. } }else{ // No. There is no user logged in. } } add_action('init', 'auto_downgrade_membership_type');January 23, 2018 at 1:27 am #13090mbrsolution
ModeratorThank you for sharing your code. Just one question, is this function added to help the following addon? Or is this function working on its own?
Kind regards
January 23, 2018 at 1:59 am #13100Daniel
ParticipantOn it’s own.
August 5, 2018 at 4:11 pm #15123E-Artisan
ParticipantHello Daniel,
Excellent function! I spent a few hours configuring our membership scheme using Simple Membership and then realised that it doesn’t have the auto-downgrade feature built in. Is there anyway we can run this function regardless of their online status? We have a member directory where paid members get to enter more details about them. With the current set up, even after they cancel their subscription, directory shows all their details as it checks their role to decide whether to display it or not.
Is there any way we can set this up to run once a day to scan everything and downgrade memberships (in my case role change)? Or any other suggestions are highly appreciated.
Thanks and regards,
-
AuthorPosts
- You must be logged in to reply to this topic.