Created
January 13, 2024 16:37
-
-
Save ideadude/92525cec18f6cf67056f998abe7971cb to your computer and use it in GitHub Desktop.
Don't let existing members checkout for a free level. [Paid Memberships Pro]
This file contains 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
/** | |
* Don't let existing members checkout for a free 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. | |
* 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_registration_checks_stop_free_checkouts( $okay ) { | |
global $pmpro_level; | |
// Bail if some other check failed already. | |
if( ! $okay ) { | |
return $okay; | |
} | |
$free_level_id = 1; // Set to the id of your free level. | |
if( pmpro_hasMembershipLevel() && (int)$pmpro_level->id === (int)$free_level_id ) { | |
pmpro_setMessage( "Your existing level has access to everything the Free level does. If you'd still like to change your level, please <a href='" . esc_url( pmpro_url( 'cancel' ) ) . "'>cancel first</a>.", 'pmpro_error' ); | |
$okay = false; | |
} | |
return $okay; | |
} | |
add_action( 'pmpro_registration_checks', 'my_pmpro_registration_checks_stop_free_checkouts' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment