Find out when a user has unsubscribed from a subscription membership plugin

I need to know when a certain user has unsubscribed form one of my subscription plans. No info like that is in the "All Members" section. Only place is in the "news" area in the main Membership section of the plugin. But there is no option to go back further in dates to see the activity. Is there a way to find this information out?

  • Patrick
    • Support Monkey

    Hey there @KerplunkDesign

    I hope you're having a great day!

    That's actually a very good question. Unfortunately, I do not the answer as there is no built-in way to fetch that data.

    So I'll see if one of our 2nd-level support wiz-kids can join in here to provide some insight.

  • Jude
    • DEV MAN

    Hey there @KerplunkDesign

    I hope you're having a great day!

    I need to know when a certain user has unsubscribed form one of my subscription plans.

    How would you like to know ? Do you want a email notification or do you want that data in a file ? Currently the news widget shows 50 messages, you can increase that maybe ?

    Cheers
    Jude

  • Jude
    • DEV MAN

    Hey there @KerplunkDesign

    Just copy paste this code into your functions.php file or better still a site specific code plugin if you use one.

    add_action( 'membership_expire_subscription', 'notify_expiry', 10, 2 );
    	function notify_expiry( $sub_id, $user_id ) {
    		$user = get_userdata($user_id);
    		$sub = Membership_Plugin::factory()->get_subscription( $sub_id );
    
    		$to = 'put_your_email@here.com' ;
    		$subject = "Membership Expiry" ;
    		$message = sprintf(__( '<strong>%s</strong> has left subscription <strong>%s</strong>','membership' ), $user->display_name, $sub->sub_name() );
    
    		wp_mail( $to, $subject, $message );
    	}

    Remember to replace the $to address with your own email

    Cheers
    Jude

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.