Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This lets you create a fixed expiration date for a membership level in Paid Memberships Pro
/*
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($level)
{
//add to this array (level ID) => (expiration date in yyy-mm-dd)
$custom_expirations = array("1" => "2013-01-01");
//needed below
$todays_date = time();
//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");
@got2brew

This comment has been minimized.

Copy link

commented May 15, 2016

Where would I insert this code? (pretty much a novice at any coding)

@jameswitika

This comment has been minimized.

Copy link

commented May 25, 2016

You should be able to post this in your functions.php file (hopefully you are using a child theme so it does not get overwritten when the theme updates).

@tbrittonb

This comment has been minimized.

Copy link

commented Jul 8, 2016

i am like got2brew.. pretty much a novice at any coding..
how do i find out if my theme is a child theme? before i insert this code?
also,, can one expound on what has to happen for (Note, this will need to be tweaked to work with PayPal Standard.)
we are planning on using paypal standard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.