Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Restrict a membership level to no longer allow sign ups after a given date (limited time offer) using Paid Memberships pro
<?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_end_date, $pmproml_limited_level_id;
$pmproml_limited_level_id = 1; // change to the ID of the limited-time membership level
$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;
$level_id = intval( $_REQUEST['level'] );
$date_format = "Y/m/d";
$registration_date = date($date_format);
$limited_level = pmpro_getLevel( $pmproml_limited_level_id );
if( $registration_date >= $pmproml_end_date && $pmproml_limited_level_id == $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;
$date_format = "Y/m/d";
$registration_date = date($date_format);
$limited_level = pmpro_getLevel( $pmproml_limited_level_id );
if( $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' => $pmproml_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
You can’t perform that action at this time.