Skip to content

Instantly share code, notes, and snippets.

@JarrydLong
Created December 19, 2024 08:32
Show Gist options
  • Save JarrydLong/f37673023ab8309091ef92c67c83c74d to your computer and use it in GitHub Desktop.
Save JarrydLong/f37673023ab8309091ef92c67c83c74d to your computer and use it in GitHub Desktop.
<?php //do not copy
/**
* This recipe hides a membership level between two dates. This can be done with multiple levels,
* in this case referencing level x and y for levels 2 and 3.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_levels_array($levels) {
//get the current date
$today = current_time( 'timestamp' );
//Hide level 2 from 2024-12-01 until 2024-12-31
$hide_level_x_after = strtotime( '2024-12-01 23:59:59' );
$hide_level_x_before = strtotime( '2024-12-31 23:59:59' );
if( ( $today > $hide_level_x_after ) && ( $today < $hide_level_x_before ) ) {
unset($levels[2]);
}
//Hide level 3 from 2025-01-01 until 2025-01-31
$hide_level_y_after = strtotime( '2025-01-01 23:59:59' );
$hide_level_y_before = strtotime( '2025-01-31 23:59:59' );
if( $today > $hide_level_y_after && $today < $hide_level_y_before ) {
unset($levels[3]);
}
return $levels;
}
add_filter('pmpro_levels_array', 'my_pmpro_levels_array');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment