pmpro_checkout_level_extend_memberships

If checking out for the same level, add remaining days to the enddate.

Description

pmpro_checkout_level_extend_memberships( $level ); 

Pulled in from: https://gist.github.com/3678054

Parameters (1)

0. $level
The level.

Usage

  1. if ( !function_exists( 'pmpro_checkout_level_extend_memberships' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/includes/filters.php'; 
  3.  
  4. // The level. 
  5. $level = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = pmpro_checkout_level_extend_memberships($level); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/filters.php  
  1. function pmpro_checkout_level_extend_memberships($level) 
  2. {  
  3. global $pmpro_msg, $pmpro_msgt; 
  4.  
  5. //does this level expire? are they an existing user of this level? 
  6. if(!empty($level) && !empty($level->expiration_number) && pmpro_hasMembershipLevel($level->id)) 
  7. //get the current enddate of their membership 
  8. global $current_user; 
  9. $expiration_date = $current_user->membership_level->enddate; 
  10.  
  11. //calculate days left 
  12. $todays_date = current_time('timestamp'); 
  13. $time_left = $expiration_date - $todays_date; 
  14.  
  15. //time left? 
  16. if($time_left > 0) 
  17. //convert to days and add to the expiration date (assumes expiration was 1 year) 
  18. $days_left = floor($time_left/(60*60*24)); 
  19.  
  20. //figure out days based on period 
  21. if($level->expiration_period == "Day") 
  22. $total_days = $days_left + $level->expiration_number; 
  23. elseif($level->expiration_period == "Week") 
  24. $total_days = $days_left + $level->expiration_number * 7; 
  25. elseif($level->expiration_period == "Month") 
  26. $total_days = $days_left + $level->expiration_number * 30; 
  27. elseif($level->expiration_period == "Year") 
  28. $total_days = $days_left + $level->expiration_number * 365; 
  29.  
  30. //update number and period 
  31. $level->expiration_number = $total_days; 
  32. $level->expiration_period = "Day"; 
  33.  
  34. return $level;