Title: Expiration Problem
Last modified: December 3, 2017

---

# Expiration Problem

 *  Resolved [Leinad4Mind](https://wordpress.org/support/users/leinad4mind/)
 * (@leinad4mind)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/expiration-problem/)
 * Hi there, when the users expire they are not being moved to the group I selected:
 *     ```
       /*
       	When users cancel (are changed to membership level 0) we give them another "cancelled" level. 
       	Can be used to downgrade someone to a free level when they cancel.
       	Will allow members to the "cancel level" to cancel from that though.
       */
       function my_pmpro_after_change_membership_level($level_id, $user_id)
       {
       	//set this to the id of the level you want to give members when they cancel
       	$cancel_level_id = 5;
   
       	//are they cancelling?
       	if($level_id == 0)
       	{
       		//check if they are cancelling from level $cancel_level_id
       		global $wpdb;
       		$last_level_id = $wpdb->get_var("SELECT membership_id FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . $user_id . "' ORDER BY id DESC");
       		if($last_level_id == $cancel_level_id)
       			return;	//let them cancel
   
       		//otherwise give them level $cancel_level_id instead
       		pmpro_changeMembershipLevel($cancel_level_id, $user_id);
       	}
       }
       add_action("pmpro_after_change_membership_level", "my_pmpro_after_change_membership_level", 10, 2);
       ```
   
 * Why it doesn’t change? Why the users goes to the expired level? Instead of the
   one I told (level 5) ?
    -  This topic was modified 8 years, 5 months ago by [Leinad4Mind](https://wordpress.org/support/users/leinad4mind/).

Viewing 15 replies - 1 through 15 (of 19 total)

1 [2](https://wordpress.org/support/topic/expiration-problem/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/expiration-problem/page/2/?output_format=md)

 *  Plugin Author [Andrew Lima](https://wordpress.org/support/users/andrewza/)
 * (@andrewza)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/expiration-problem/#post-9747538)
 * Hi [@leinad4mind](https://wordpress.org/support/users/leinad4mind/),
 * Thank you for using Paid Memberships Pro. This code looks correct.
 * We are able to help troubleshoot why it’s not working. Please can you open a 
   support thread on [https://www.paidmembershipspro.com](https://www.paidmembershipspro.com)
 * Here is documentation revolving around this – [https://www.paidmembershipspro.com/change-membership-level-on-cancellation-or-expiration/](https://www.paidmembershipspro.com/change-membership-level-on-cancellation-or-expiration/)
 * The code you are using is if you have setup your membership to have tiered (higher
   and lower levels).
 * I hope this helps.
 *  Thread Starter [Leinad4Mind](https://wordpress.org/support/users/leinad4mind/)
 * (@leinad4mind)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/expiration-problem/#post-9747655)
 * The user level IDs are 3 and when it expire it needs to go to 5 not to expire.
 * Is this code only for cancellation or it should work too for expiration?
 * I can’t see nothing in the link provided…
    -  This reply was modified 8 years, 5 months ago by [Leinad4Mind](https://wordpress.org/support/users/leinad4mind/).
    -  This reply was modified 8 years, 5 months ago by [Leinad4Mind](https://wordpress.org/support/users/leinad4mind/).
 *  Plugin Author [Andrew Lima](https://wordpress.org/support/users/andrewza/)
 * (@andrewza)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/expiration-problem/#post-9747710)
 * This code should work for both expiration and cancellation.
 * I have taken a look at the link and you will need an account to access the content.
 *  Thread Starter [Leinad4Mind](https://wordpress.org/support/users/leinad4mind/)
 * (@leinad4mind)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/expiration-problem/#post-9747739)
 * Ive an account.
    I saw that there was an update on the gist. Anyway, this still
   should work but it doesn’t.
    -  This reply was modified 8 years, 5 months ago by [Leinad4Mind](https://wordpress.org/support/users/leinad4mind/).
 *  Plugin Author [Andrew Lima](https://wordpress.org/support/users/andrewza/)
 * (@andrewza)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/expiration-problem/#post-9747834)
 * Thanks for this, if you have an account on paidmembershipspro.com please can 
   you open a support thread on there so we may troubleshoot your code.
 *  Thread Starter [Leinad4Mind](https://wordpress.org/support/users/leinad4mind/)
 * (@leinad4mind)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/expiration-problem/#post-9747907)
 * I can’t go to the Support Forum, I would need to buy a plan. I don’t need a plan
   for this, at least for now. If the free plugin doesn’t work at all and is full
   of bugs why should I buy it?
 * This code was provided in the past here. But the code doesn’t work… I guess I’ll
   need to edit core files.
 *  Plugin Author [Andrew Lima](https://wordpress.org/support/users/andrewza/)
 * (@andrewza)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/expiration-problem/#post-9748374)
 * I do not recommend editing core files as once you update your custom code will
   be overwritten.
 * You mentioned that Paid Memberships Pro is full of bugs, would you mind pointing
   these out to me so I may add this to our development schedule so we may fix these
   bugs as soon as possible?
 * Also I have done another once-over on your code to see what could be causing 
   this not to work, please try the following code – [https://gist.github.com/strangerstudios/5703500#file-pmpro_cancelled_level-php](https://gist.github.com/strangerstudios/5703500#file-pmpro_cancelled_level-php)
 * This code will not run if there is a next payment date for the particular user,
   such as a recurring subscription. This will assign a user to a particular level
   when they cancel, regardless of the level they are canceling. Would this work
   for you?
 * I do highly recommend in getting a premium account so you may get higher more
   technical support than what we offer on our .org forums and help troubleshoot
   your custom code, such as this thread’s query.
 * The code gist above should solve your problem, I have tested it on my local environment
   and it works as intended.
 * Please let me know about the bugs you are facing so I may attend to these with
   high priority.
    -  This reply was modified 8 years, 5 months ago by [Andrew Lima](https://wordpress.org/support/users/andrewza/).
 *  Thread Starter [Leinad4Mind](https://wordpress.org/support/users/leinad4mind/)
 * (@leinad4mind)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/expiration-problem/#post-9748494)
 * Thanks. I’ll do some tests. One last doubt, how can I simulate this without waiting
   a full day to pass?
 *  Plugin Author [Andrew Lima](https://wordpress.org/support/users/andrewza/)
 * (@andrewza)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/expiration-problem/#post-9751398)
 * What you will need to do is create a member and backdate their expiration date.
 * You then can run the expiration code by going to `https://yourwebsite.com/wp-
   content/plugins/paid-memberships-pro/scheduled/expirememberships.php` in your
   browser.
 * This will manually run and expire the user’s membership.
 *  Thread Starter [Leinad4Mind](https://wordpress.org/support/users/leinad4mind/)
 * (@leinad4mind)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/expiration-problem/#post-9764331)
 * Strange because I run that and I get a blank page and nothing happens.
 *  Thread Starter [Leinad4Mind](https://wordpress.org/support/users/leinad4mind/)
 * (@leinad4mind)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/expiration-problem/#post-9766615)
 * I was sleeping yesterday -.- I put the wrong year LOOL
 * Thanks! That helped!
 * PS:
 *  //if we see this global set, then another gist is planning to give the user 
   their level back
    global $pmpro_next_payment_timestamp; if(!empty($pmpro_next_payment_timestamp))
   return;
 * Can you tell me what does this code really do? Just to be sure I need it in my
   code or not.
    -  This reply was modified 8 years, 5 months ago by [Leinad4Mind](https://wordpress.org/support/users/leinad4mind/).
 *  Thread Starter [Leinad4Mind](https://wordpress.org/support/users/leinad4mind/)
 * (@leinad4mind)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/expiration-problem/#post-9825281)
 * Hi there, I need to reopen this, I’ve more information about the bug.
 * See this image please:
 * > [View post on imgur.com](https://imgur.com/3ygiGea)
 * I had 4 users that were moved to the cancel group.
 * This is my settings: [https://i.imgur.com/lonO3uK.png](https://i.imgur.com/lonO3uK.png)
 * When they renew the end date should be 1 year later and not the end of the current
   year!
 *  Thread Starter [Leinad4Mind](https://wordpress.org/support/users/leinad4mind/)
 * (@leinad4mind)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/expiration-problem/#post-9825398)
 * This user was moved to cancel group instead Free Member: [https://i.imgur.com/B8itY12.png](https://i.imgur.com/B8itY12.png)
 * As we can see it have been put on Free member but the end date was not changed
   to Never 🙁
    So I beleive that the date is causing the issue, since maybe after
   the date ends the users is moved to cancel group.
 *  Thread Starter [Leinad4Mind](https://wordpress.org/support/users/leinad4mind/)
 * (@leinad4mind)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/expiration-problem/#post-9825595)
 * About the 4 users that renew, they all have the same thing in common, they all
   were still on an membership plan when they renew. I’ve others users that renew
   after the membership plan expired, and it was all good with their account.
 * So there is some bug when users renew when still on a valid membership. It should
   change the end date.
 *  Plugin Author [Andrew Lima](https://wordpress.org/support/users/andrewza/)
 * (@andrewza)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/expiration-problem/#post-9846337)
 * Thank you for your patience regarding this.
 * Are you running any custom code that will alter the expiration date such as to
   only cancel the user’s account on their next payment date and not immediately?
 * Please let me know.

Viewing 15 replies - 1 through 15 (of 19 total)

1 [2](https://wordpress.org/support/topic/expiration-problem/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/expiration-problem/page/2/?output_format=md)

The topic ‘Expiration Problem’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/paid-memberships-pro_f1dacb.svg)
 * [Paid Memberships Pro - Content Restriction, User Registration, & Paid Subscriptions](https://wordpress.org/plugins/paid-memberships-pro/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/paid-memberships-pro/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/paid-memberships-pro/)
 * [Active Topics](https://wordpress.org/support/plugin/paid-memberships-pro/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/paid-memberships-pro/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/paid-memberships-pro/reviews/)

 * 19 replies
 * 2 participants
 * Last reply from: [Andrew Lima](https://wordpress.org/support/users/andrewza/)
 * Last activity: [8 years, 4 months ago](https://wordpress.org/support/topic/expiration-problem/page/2/#post-9868057)
 * Status: resolved