MemberPress: Send Existing Members From Sign-Up Pages to Their Account
Redirects logged-in members who already own a membership away from that membership's sign-up page to their account page, avoiding accidental double purchases.
Opens WPIDE on
Code
if ( ! class_exists( 'MeprUser' ) || ! class_exists( 'MeprProduct' ) ) {
return;
}
$wpide_mepr_account_url = home_url( '/account/' );
add_action( 'template_redirect', function () use ( $wpide_mepr_account_url ) {
if ( ! is_user_logged_in() || ! is_singular( MeprProduct::$cpt ) ) {
return;
}
$member = new MeprUser( get_current_user_id() );
if ( $member->is_already_subscribed_to( get_queried_object_id() ) ) {
wp_safe_redirect( $wpide_mepr_account_url );
exit;
}
} );
Notes
Members can still buy other memberships; only the one they already have redirects.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.