Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ideadude/92525cec18f6cf67056f998abe7971cb to your computer and use it in GitHub Desktop.
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]
/**
* 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