Forked from JarrydLong/pmpro-limited-time-registration.php
Created
March 11, 2022 18:11
-
-
Save MaryOJob/a4da048fdbbfef7df8b2d1d7f2b77960 to your computer and use it in GitHub Desktop.
Restrict a membership level to no longer allow sign ups after a given date (limited time offer) using 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
<?php | |
/* Checks to see if a registration is happening after a given date; if so, prevent registration and stop new signups for the level/no longer display the level on the levels page | |
*/ | |
global $pmproml_start_date, $pmproml_end_date, $pmproml_limited_level_id; | |
$pmproml_limited_level_id = array( 1, 2, 4 ); // change to the ID of the limited-time membership level | |
$pmproml_start_date = "2019/04/01"; // change to the date registration starts, in YYYY/MM/DD format | |
$pmproml_end_date = "2019/04/30"; // change to the date registration ends, in YYYY/MM/DD format | |
function pmproml_pmpro_registration_date_checks( $value ) { | |
global $wpdb, $pmproml_end_date, $pmproml_limited_level_id, $pmproml_start_date; | |
$level_id = intval( $_REQUEST['level'] ); | |
$date_format = "Y/m/d"; | |
$registration_date = date($date_format); | |
if( !empty( $pmproml_limited_level_id ) ){ | |
foreach( $pmproml_limited_level_id as $limited_level_id ){ | |
$limited_level = pmpro_getLevel( $limited_level_id ); | |
if( ( $registration_date <= $pmproml_start_date || $registration_date >= $pmproml_end_date ) && in_array( $level_id, $limited_level_id ) ) { | |
global $pmpro_msg, $pmpro_msgt; | |
$pmpro_msg = __( "Memberships for this level are no longer available as of $pmproml_end_date", 'paid-memberships-pro' ); | |
$pmpro_msgt = "pmpro_error"; | |
$wpdb->update( | |
$wpdb->pmpro_membership_levels, | |
array( | |
'allow_signups' => 0 | |
), | |
array( | |
'id' => $level_id | |
) | |
); | |
$value = false; | |
} | |
} | |
} | |
return $value; | |
} | |
add_filter( 'pmpro_registration_checks', 'pmproml_pmpro_registration_date_checks', 10, 1 ); | |
function pmproml_pmpro_hide_limited_levels( $pmpro_levels ) { | |
global $wpdb, $pmproml_end_date, $pmproml_limited_level_id, $pmproml_start_date; | |
$date_format = "Y/m/d"; | |
$registration_date = date($date_format); | |
if( !empty( $pmproml_limited_level_id ) ){ | |
foreach( $pmproml_limited_level_id as $limited_level_id ){ | |
$limited_level = pmpro_getLevel( $limited_level_id ); | |
if( ( $registration_date <= $pmproml_start_date || $registration_date >= $pmproml_end_date ) && isset( $limited_level->allow_signups ) && $limited_level->allow_signups != 0 ) { | |
$wpdb->update( | |
$wpdb->pmpro_membership_levels, | |
array( | |
'allow_signups' => 0 | |
), | |
array( | |
'id' => $limited_level_id | |
) | |
); | |
} | |
} | |
} | |
return $pmpro_levels; | |
} | |
add_filter('pmpro_levels_array', 'pmproml_pmpro_hide_limited_levels', 10, 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment