Membership Plugin

WordPress Membership Plugin

  • Home
  • Documentation
  • Addons
  • Support
    • Quick Setup
    • Documentation
    • Premium Addon Support
    • Paid Support
    • Support Forum
    • Support Forum Search
    • Forum Login
    • Forum Registration
  • Contact

[Resolved] Downgrade account instead of expire?

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.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • January 20, 2018 at 1:47 am #13048
    Daniel
    Participant

    I 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 #13049
    mbrsolution
    Moderator

    Hi, 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 #13078
    Daniel
    Participant

    Unfortunately 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 #13079
    mbrsolution
    Moderator

    Hi, 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 #13083
    Daniel
    Participant

    I 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 #13085
    mbrsolution
    Moderator

    I 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 #13087
    Daniel
    Participant

    I 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 #13090
    mbrsolution
    Moderator

    Thank 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 #13100
    Daniel
    Participant

    On it’s own.

    August 5, 2018 at 4:11 pm #15123
    E-Artisan
    Participant

    Hello 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,

  • Author
    Posts
Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.
Log In

Please read this message before using our plugin.

Search

Featured Addons and Extensions

  • Membership Form Builder Addon
  • Member Directory Listing Addon
  • WooCommerce Payment Integration
  • Member Data Exporter Addon

Documentation

  • Documentation Index Page

Copyright © 2026 | Simple Membership Plugin | Privacy Policy