Membership isn't downgraded automatically, instead user is deleted

I sell two types of products on my site:

  1. Online course for a one-time fee. Bronze, Silver, Gold packages (Level 1, 2, 3)
  2. Subscription based report, billed monthly or annually (Level 4, 5, 6)

I setup my membership levels like this:

Level 1: customer who only buys the Bronze package course
Level 2: customer who only buys the Silver package course
Level 3: customer who only buys the Gold package course
Level 4: Bronze package + subscription to my report
Level 5: Silver package + subscription to my report
Level 6: Gold package + subscription to my report

I’m using Stripe to process the payments.

Two years ago a user bought my course Gold package (Level 3), then on March 30, 2016 he subscribed to my report so he got moved to a Level 6. After 12 months he decided not to renew the subscription, also he didn’t update his credit card information so naturally the payment did not go thru.

However his membership account got automatically deleted in Wordpress, it should have gone from Level 6 back to Level 3. This has happened to four other members on my site.

Is there a way in s2member to ensure that membership levels are automatically downgraded, instead of deleted?

thanks!

See Stripe Options -> Automatic EOT Behavior

Thanks Tim for the quick reply.

I only see two options under Automatic EOT Behavior:

  • Demote (convert them to a free subscriber)
  • Delete (erase their account completely)

Unfortunately neither of these options work for me. I need the demote to work like this:

  • if at Level 4 and user cancels subscription, demote to Level 1 so user can still access the course
  • if at Level 5 and user cancels subscription, demote to Level 2 so user can still access the course
  • if at Level 6 and user cancels subscription, demote to Level 3 so user can still access the course

Any ideas on how I can accomplish this?

This is untested, but you could try putting something like this into an mu-plugin:

<?php
function user_role_update_on_demotion( $user_id, $new_role, $old_role ) {
	$user = get_userdata( $user_id );
        
	if ( $old_role == 's2member_level6' && $new_role == 's2member_level0' ) {
		$user->add_role( 's2member_level3' );
	}
	else if ( $old_role == 's2member_level5' && $new_role == 's2member_level0' ) {
		$user->add_role( 's2member_level2' );
	}
	else if ( $old_role == 's2member_level4' && $new_role == 's2member_level0' ) {
		$user->add_role( 's2member_level1' );
	}
}
add_action( 'set_user_role', 'user_role_update_on_demotion', 10, 3);

This assumes that you choose to demote from the s2Member settings available.

You might need to use subscriber instead of s2member_level0