Created
May 21, 2025 11:19
-
-
Save JarrydLong/2f5426d587fc2ae39db1685ac93414df to your computer and use it in GitHub Desktop.
This file contains hidden or 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 //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