• Resolved Leinad4Mind

    (@leinad4mind)


    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 5 years, 9 months ago by Leinad4Mind.
Viewing 15 replies - 1 through 15 (of 19 total)
  • Plugin Author Andrew Lima

    (@andrewza)

    Hi @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

    Here is documentation revolving around this – 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

    (@leinad4mind)

    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 5 years, 9 months ago by Leinad4Mind.
    • This reply was modified 5 years, 9 months ago by Leinad4Mind.
    Plugin Author Andrew Lima

    (@andrewza)

    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

    (@leinad4mind)

    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 5 years, 9 months ago by Leinad4Mind.
    Plugin Author Andrew Lima

    (@andrewza)

    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

    (@leinad4mind)

    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

    (@andrewza)

    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

    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 5 years, 9 months ago by Andrew Lima.
    Thread Starter Leinad4Mind

    (@leinad4mind)

    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

    (@andrewza)

    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

    (@leinad4mind)

    Strange because I run that and I get a blank page and nothing happens.

    Thread Starter Leinad4Mind

    (@leinad4mind)

    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 5 years, 9 months ago by Leinad4Mind.
    Thread Starter Leinad4Mind

    (@leinad4mind)

    Hi there, I need to reopen this, I’ve more information about the bug.

    See this image please:
    https://i.imgur.com/3ygiGea.png

    I had 4 users that were moved to the cancel group.

    This is my settings: 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

    (@leinad4mind)

    This user was moved to cancel group instead Free Member: 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

    (@leinad4mind)

    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

    (@andrewza)

    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)
  • The topic ‘Expiration Problem’ is closed to new replies.