Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Forked from chrislema/PMPExpirationDate
Last active April 16, 2021 23:39
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save strangerstudios/5709300 to your computer and use it in GitHub Desktop.
Save strangerstudios/5709300 to your computer and use it in GitHub Desktop.
Set a specific expiration date for a Membership Level.
/*
For a level to expire on a certain date.
(Note, this will need to be tweaked to work with PayPal Standard.)
*/
function my_pmpro_checkout_level_specific_expiration($level)
{
//ignore renewals (they will be pushed out one payment period)
if(pmpro_hasMembershipLevel($level->id))
return $level;
//add to this array (level ID) => (expiration date in yyyy-mm-dd)
$nextyear = intval(date("Y")) + 1;
$custom_expirations = array("1" => $nextyear . "-01-01");
//needed below
$todays_date = current_time('timestamp');
//check the passed level against your array
foreach($custom_expirations as $level_id => $expiration_date)
{
//custom expiration?
if($level->id == $level_id)
{
//how many days until expiration?
$time_left = strtotime($expiration_date) - $todays_date;
if($time_left > 0)
{
$days_left = ceil($time_left/(60*60*24));
//update number and period
$level->expiration_number = $days_left;
$level->expiration_period = "Day";
return $level; //stop
}
else
{
//expiration already here, don't let people signup
$level = NULL;
return $level; //stop
}
}
}
return $level; //no change
}
add_filter("pmpro_checkout_level", "my_pmpro_checkout_level_specific_expiration");
@crsouser
Copy link

This is a great add-on to the PMPro, would love it even more if it were integrated, so the Subscription text reflected it, as well as the functionality of my_pmpro_level_expiration_text.php was also possibly integrated.

I look forward to the enhancement for recurring paypal standard support to on a set date.

Thanks!
Christopher

@laurenhagan0306
Copy link

This recipe is included in the blog post on "Have All Members Expire on a Set Date" at Paid Memberships Pro here: https://www.paidmembershipspro.com/have-all-members-expire-on-a-set-date/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment