Created
February 9, 2017 16:29
-
-
Save andrewlimaza/81dd0bbf3835b299e1901b83498bf851 to your computer and use it in GitHub Desktop.
Don't allow users to checkout for the same level in PMPro if date is more than 3 months
This file contains hidden or 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
<?php | |
/* | |
Don't allow early renewals for certain levels. | |
(Don't allow users to checkout for the same level in PMPro if date is more than 3 months) | |
Change the level IDs in the $pmpro_non_renewal_levels global array, then | |
add this code to your active theme's functions.php or a custom plugins. | |
Add the following code to your PMPro Customizations plugin -> http://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
//define levels in global | |
global $pmpro_non_renewal_levels; | |
$pmpro_non_renewal_levels = array(1,2,3,4,5); //change this to the level IDs of the levels you don't want users to renew for | |
//hide the renew link | |
function hide_renewal_links_for_some_levels($r, $level) { | |
global $pmpro_non_renewal_levels; | |
if(in_array($level->id, $pmpro_non_renewal_levels)) | |
$r = false; | |
return $r; | |
} | |
add_action('pmpro_is_level_expiring_soon', 'hide_renewal_links_for_some_levels', 10, 2); | |
//redirect from checkout page to the membership account page | |
function redirect_non_renewing_levels() { | |
global $pmpro_non_renewal_levels, $current_user; | |
//make sure pmpro is active | |
if(!function_exists('pmpro_hasMembershipLevel')) | |
return; | |
$enddate = $current_user->membership_level->enddate; | |
$today = current_time('timestamp'); | |
$days_until_enddate = ceil(($enddate-$today)/3600/24); | |
//if we're checking out, redirect to account page - change 180 to the number of days you would like users to checkout again. | |
if($days_until_enddate >= 180){ | |
if(!is_admin() && !empty($_REQUEST['level']) && in_array($_REQUEST['level'], $pmpro_non_renewal_levels) && pmpro_hasMembershipLevel(intval($_REQUEST['level']))) { | |
wp_redirect(add_query_arg('norenewal', '1', pmpro_url('account'))); | |
exit; | |
} | |
} | |
} | |
add_action('template_redirect', 'redirect_non_renewing_levels'); | |
//show message on the account page | |
function the_content_add_non_renewal_message($content) { | |
global $pmpro_pages; | |
if(!empty($pmpro_pages) && is_page($pmpro_pages['account']) && !empty($_REQUEST['norenewal'])) | |
$content = "<p><strong>You must wait before renewing your membership.</strong></p>" . $content; | |
return $content; | |
} | |
add_filter('the_content', 'the_content_add_non_renewal_message'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment