Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dynamically display certain levels on the Membership Levels page based on the current user's active level
<?php
/**
* Dynamically display certain levels on the Membership Levels page based on the current user's active level
* This example allows you to show/hide specific levels on the Membership Levels page.
*/
function dynamic_pmpro_levels_array( $levels ) {
// Get all the levels
$levels = pmpro_getAllLevels( false, true );
// remove levels 1, 5, 6, and 7 user has level 1.
if ( pmpro_hasMembershipLevel( '1' ) ) {
unset( $levels['1'] );
unset( $levels['5'] );
unset( $levels['6'] );
unset( $levels['7'] );
}
// remove levels 1, 2, 3, and 4 if user has level 2.
if ( pmpro_hasMembershipLevel( '2' ) ) {
unset( $levels['1'] );
unset( $levels['2'] );
unset( $levels['3'] );
unset( $levels['4'] );
}
// only show levels 1 and 2 if user has no level.
if ( ! pmpro_hasMembershipLevel( ) ) {
unset( $levels['3'] );
unset( $levels['4'] );
unset( $levels['5'] );
unset( $levels['6'] );
unset( $levels['7'] );
}
return $levels;
}
add_filter( 'pmpro_levels_array', 'dynamic_pmpro_levels_array', 10, 2 );
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.