Skip to content

Instantly share code, notes, and snippets.

@chrislema
Created December 17, 2012 04:21
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save chrislema/4315730 to your computer and use it in GitHub Desktop.
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
Copy link

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

@jameswitika
Copy link

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
Copy link

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