Home / Archive / MemberPress: Change Membership Registration URL
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Change Membership Registration URL

Each MemberPress Membership has an automatically generated registration page with its default URL.

This code snippet will replace the default registration page URL with a custom URL. This way, a custom registration page can be created, and set to be used instead of the default one.

The code must be adjusted to match the real membership. Thus, a dummy membership ID of 123 should be replaced with the ID of the actual membership (Membership IDs are available at Dashboard > MemberPress > Memberships), on the following line:

case '123':

Also, the dummy page ID of 456 should be replaced with the real ID of the custom registration page, on this line:

$url = MeprUtils::get_permalink( 456 ).$args;

Code Preview
php
<?php
function mepr_change_membership_urls( $url, $product, $args, $modify_if_https ) {
  $url_changed = false;
	
  switch( $product->ID ) {
    case '123': //Change 123 to membership id where you can get it from ID column from Membership table
      $url = MeprUtils::get_permalink( 456 ).$args; //Change 456 to custom registration page id. Page ID is available within the page URL while editing the page (“post=” part of the URL)
      $url_changed = true;
    break;
     
      // Copy the above case block and paste it here to add additional memberships 
      // case 'new_membership_id': 
      // $url = MeprUtils::get_permalink(new_page_id) . $args; 
      // $url_changed = true; 
      // break;
      }
  if( $url_changed && MeprUtils::is_ssl() && $modify_if_https ) {
    $url = preg_replace( '!^http:!','https:',$url );
  }
  return $url;
}
add_filter( 'mepr-product-url', 'mepr_change_membership_urls', 10, 4 );

Comments

Add a Comment