Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JarrydLong/2f5426d587fc2ae39db1685ac93414df to your computer and use it in GitHub Desktop.
Save JarrydLong/2f5426d587fc2ae39db1685ac93414df to your computer and use it in GitHub Desktop.
<?php //do not copy
/**
* This recipe set the default level on the checkout page to the member's current level
*
* 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.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_default_level_from_current_user($default_level) {
$user_id = get_current_user_id();
if( ! $user_id ) {
return $default_level;
}
$level = pmpro_getMembershipLevelForUser($user_id);
if ( empty( $level ) ) {
return $default_level;
}
return $level->id;
}
add_filter('pmpro_default_level', 'my_pmpro_default_level_from_current_user', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment