-
-
Save greathmaster/67c90f5a8906d14d6586 to your computer and use it in GitHub Desktop.
Extend Expiration Dates For Renewed Memberships in Paid Memberships Pro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Modified to transfer over unused days from old level into new level. For example: | |
Level 1 expires in 30 days and Level 2 expires in 180 days. If a members signs up | |
for Level 1 and 5 days in decides to up upgreade to Level 2, thier new expiry date | |
will be (30 - 5) + 180 days. | |
*/ | |
//if checking out for the same level, add remaining days to the enddate | |
function my_pmpro_checkout_level($level) | |
{ | |
global $pmpro_msg, $pmpro_msgt; | |
//does this level expire? are they an existing user of a different level? | |
if($level->expiration_number && !pmpro_hasMembershipLevel($level->id)) | |
{ | |
//get the current enddate of their membership | |
global $current_user; | |
$expiration_date = $current_user->membership_level->enddate; | |
//calculate days left | |
$todays_date = time(); | |
$time_left = $expiration_date - $todays_date; | |
//time left? | |
if($time_left > 0) | |
{ | |
//convert to days and add to the expiration date (assumes expiration was 1 year) | |
$days_left = floor($time_left/(60*60*24)); | |
//figure out days based on period | |
if($level->expiration_period == "Day") | |
$total_days = $days_left + $level->expiration_number; | |
elseif($level->expiration_period == "Week") | |
$total_days = $days_left + $level->expiration_number * 7; | |
elseif($level->expiration_period == "Month") | |
$total_days = $days_left + $level->expiration_number * 30; | |
elseif($level->expiration_period == "Year") | |
$total_days = $days_left + $level->expiration_number * 365; | |
//update number and period | |
$level->expiration_number = $total_days; | |
$level->expiration_period = "Day"; | |
} | |
} | |
return $level; | |
} | |
add_filter("pmpro_checkout_level", "my_pmpro_checkout_level"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment