Upgrade member to next level after subscription payment
-
LOVE LOVE LOVE S2Member.
Knowledge level: Object Oriented Programmer – though no PHP
Situation:
There are three types of content access – Basic, Plus, and Pro identified by custom capabilities (basic_access, plus_access, pro_access).
There are three payment options identified by custom capabilities as well (instant, 6pay, 3pay).For example: A member identified as 6pay, plus – means they are a 6 monthly payment member with access to plus content.
There are 6 levels. Each level increments access to content based on payment. Basically, I use levels to “drip content” based on payment and custom capability.
For example for a 6 pay plan:
Level 1: Access to basic, plus or pro Modules 1-4 once first payment is made
Level 2: Access to basic, plus or pro Modules 1-8 once second payment is made
Level 3: Access to basic, plus or pro Modules 1-12 once third payment is made
Level 4: Access to basic, plus or pro Modules 1-16 once fourth payment is made
Level 5: Access to basic, plus or pro Modules 1-20 once fifth payment is made
Level 6: Access to basic, plus or pro Modules 1-24 once last payment is madeIf a person made an instant payment – they would automatically have lifetime access to content (basic, pro, or plus) at level 6
If a person was on a 3 pay plan they would come in at level 2. They would get bumped to level 4 after the second payment; and then bumped to level 6 after the third payment.
The goal is to get to level 6 – whether a user does that in 1 payment, 3 payments or 6 payments is up to them.
Requirement 1:
When a user makes a payment, bump the user up to the next level. Make sure all capabilities follow that user.Requirement 2:
When a user makes their last payment (whether 3rd or 6th) – give them lifetime access and do not AUTO-EOT.Thus far I have the following code. As you look at it, consider the following questions:
Am I on the right track to reach my requirements?
Is there an easier way to complete this? A better solution?
Do you see any immediate holes?
Does the s2member_paid_registration_time look at the last time a user made a payment or the last time I moved them to a higher level? If so – what do I need to do to check the payment?
How do I stop the user’s access from expiring when they get to level 6?<?php add_action?("init",?"my_cron_job",?1); function?my_cron_job?() { if?($_GET["my_cron_job"]?===?"secret-cron-job-key") ?????{ ????? foreach?(get_users?()?as?$user) { ??????????$user?=?new?WP_User?($user->ID); $s2member_access_level = get_user_field ("s2member_access_level", $user); //The user is not a level 6 and they are on a 6pay plan if( ($s2member_access_level < 6) && $user->has_cap("6pay")) { //The last time a user made a payment $time = s2member_paid_registration_time ($s2member_access_level, $user); //30 days ago $_30_days_ago = strtotime("-30 days”) //The user has made a payment at least 30 days ago. if( $time <= $_30_days_ago) { //Get the users level switch($s2member_access_level) { case 5: //Promote the user’s level. $user->set_role("s2member_level6"); //The user has made 6 payments. Take them out of the level update cycle $user->remove_cap("6pay”); //How do I stop the user’s access from expiring. They should have lifetime access. break; case 4: $user->set_role("s2member_level5"); break; case 3: $user->set_role("s2member_level4"); break; case 2: $user->set_role("s2member_level3"); break; default: $user->set_role("s2member_level2"); break; }//end switch }//end time }//end member }//end for ????}//end if }//end function ?>
- The topic ‘Upgrade member to next level after subscription payment’ is closed to new replies.