Forked from strangerstudios/pmpro_checkout_end_date_example.php
Created
April 1, 2019 16:17
-
-
Save itsjusteileen/1c6ec39cdafcdfdda47121c3907606e4 to your computer and use it in GitHub Desktop.
Setup Level 3 to start next Monday and end the following Monday with 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
/* | |
Setup Level 3 to start next Monday and end the following Monday | |
Requires PMPro 1.8.9 or higher. | |
Add this code to your active theme's functions.php or a custom plugin. | |
*/ | |
//startdate | |
function my_pmpro_checkout_start_date($enddate, $user_id, $level) { | |
if($level->id == 3) | |
$startdate = "'" . date('Y-m-d', strtotime('next Monday', current_time('timestamp'))) . "'"; | |
return $startdate; | |
} | |
add_action('pmpro_checkout_start_date', 'my_pmpro_checkout_start_date', 10, 3); | |
//enddate | |
function my_pmpro_checkout_end_date($enddate, $user_id, $level, $startdate) { | |
if($level->id == 3 && $level->expiration_number > 0) | |
$enddate = "'" . date("Y-m-d", strtotime("+ " . $level->expiration_number . " " . $level->expiration_period, strtotime(trim($startdate,"'")) )) . "'"; | |
return $enddate; | |
} | |
add_action('pmpro_checkout_end_date', 'my_pmpro_checkout_end_date', 10, 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment