Is there a way to automatically add a new user to a membership

When someone clicks on a page that a free membership is required, then they click on register and fill out the sign up form they are then directed to the memberships list and can join the different memberships. Is there a way for a new user to be automatically signed up for a particular membership without having to click on join membership? Then I could use the change page add on to direct them to the same page that they wanted to access.

  • Adam Czajczyk
    • Support Gorilla

    Hello Mattbkelly,

    I hope you’re well today and thank you for your question1

    There’s a simple way to pre-define the membership the user’s about to signup for. To do this,, please use this shortcode:

    [ms-membership-register-user membership_id=”X”]

    where “X” is an ID of selected membership. This shortcode will display registration form allowing user to create WordPress user account and selected membership will be assigned to the user. The only exception is if the membership is paid – in such case user is redirected to the payment gateway.

    I hope that helps!

    Best regards,

    Adam

  • Mattbkelly
    • WordPress Warrior

    I used that shortcode on this page:http://kellycasa.com/market/register-as-user/

    but after signing up it still requested that I join. Is this because I am using an invitation code add-on?

    Also, would like to add the shortcode to the protected page http://kellycasa.com/market/ph but the registration form doesn’t show up because it says that the page is protected instead. I understand that it doesn’t show up because there because there is a tiny little register link at the bottom of the page. That is not obvious to most people. I would like them to see a registration button if possible.

    thanks,

    matt

  • Adam Czajczyk
    • Support Gorilla

    Hey Matt,

    I just got a code from one of our developers. It should let you automatically assign selected membership to all newly registered users upon registration. To use it, please create an empty file with a .php extension (name doesn’t matter much), copy&past the code there and then upload it to your WP install’s “/wp-content/mu-plugins” folder.

    If there’s no “mu-plugins” folder inside “/wp-content”, please create it. Here’s a code:

    <?php
    add_action( 'user_register', 'assign_membership_on_register', 10, 1 );
    function assign_membership_on_register( $user_id ) {

    $membership_id = 1343;
    $member = MS_Factory::load( 'MS_Model_Member', $user_id );
    $subscription = $member->add_membership( $membership_id );

    if ( $member->has_membership() ) {
    $member->is_member = true;
    } else {
    $member->is_member = false;
    }
    $member->save();

    }

    Also, make sure that you replaced the “1343” value in

    “$membership_id = 1343” line with an actual ID of the membership you’d like to assign.

    This way, there’ll be no need for user to visit any “special” page and upon registration he/she will be automatically given a membership right after filling registration form.

    Also, would like to add the shortcode to the protected page http://kellycasa.com/market/ph but the registration form doesn’t show up because it says that the page is protected instead. I understand that it doesn’t show up because there because there is a tiny little register link at the bottom of the page. That is not obvious to most people. I would like them to see a registration button if possible.

    I have just visited that page as a visitor/not logged in user and I was given prompt to login and a login form. I think you’ve figured it out by yourself already :slight_smile:

    In case you’d need further assistance, just let me know and I’ll be glad to help!

    Best regards,

    Adam

  • Mattbkelly
    • WordPress Warrior

    I am not quite sure what that code does. I am using http://www.massagetx.com/ph as an example (I can use the real page because it does not reveal the login form).

    After adding that code is still takes me through the same process. As a non signed in user I:

    1. I fill out the registration form

    2. It still shots me to pick a membership page (sorry it is the last screenshot out of order) – I pick it

    3. It asks for a code

    4. It asks to sign up with that code

    5. It dumps me at the registration complete screen

    Is there a way to stay on the page that they need to go to while doing the following:

    1. click on a button that says "sign up"

    2, Enter the code

    3. Fill out the form

    4. Book an appointment (the same page that is protected and they are needing to get to)

    Or even close to that? The other process is super painful and confusing. I have a large form they need to fill out and if they get the code wrong then they still can't book the appointment and they think they will need to fill out that form again.

    Ideas?

    [attachments are only viewable by logged-in members] [attachments are only viewable by logged-in members] [attachments are only viewable by logged-in members] [attachments are only viewable by logged-in members] [attachments are only viewable by logged-in members]

  • Adam Czajczyk
    • Support Gorilla

    Hello Mattbkelly,

    Thank you for your replay!

    The code is supposed to automatically assign selected membership to the user upon WP registration. That’s useful in case you’re using your own registration form and got Membership 2 registration switched off.

    There is another solution I could think of that may be much closer to what you need, except the redirection (I’ll get to it later though). Here’s what you could do.

    1. Instead of protection your page with Membership’s “Protection Rules” you could protect the content of the page with protection shortcode like this:

    [ms-protect-content id="36"]

    THIS IS CONTENT OF YOUR PAGE

    [/ms-protect-content]

    Instead of “36” value, use ID of the membership that should give access to the content.

    2. Below or above protected part (point #1) add these shortcodes:

    [ms-protect-content id="36" access="no" silent="yes"]
    [ms-membership-buy id="36"]
    [/ms-protect-content]

    Again, replace “36” with an ID of the same membership as in point #1.

    The workflow now be as follows:

    – not-logged in users will see a “protection notice” and a “signup” link

    – logged-in users that are NOT members of selected memberships will also see the “protection” notice and a “signup” link

    – logged-in users that are members of selected memberships will see protected content but will not see “signup” link

    Once user click on “Signup” link, he/she will be redirected to your current registration/login form but will not get a choice of memberships and should not be forced to select memberships. Instead after filling a registration form they’ll be instantly taken to Thank you page.

    To sum it up: “Not logged user” = “Protected notice + signup link” -> “Registration form (no membership choice” -> “Thank you page”.

    As I mentioned before, the redirect to the page in question is a downside here as this is currently not possible out of the box. The “Login redirect” of Membership 2 will not work in this case as it only redirects users that are already registered and are logging in with Membership 2 form.

    The workaround would be to place the link back to the page on “Thank you page”. In case there were no other “upon signup redirects” other than this one you could also use any WP redirect plugin to redirect “Thank you” page to the page in question.

    Let me know if this will get you any closer to the solution, please!

    Best regards,

    Adam