• fibiet

    (@fibiet)


    First of all thanks for such a great plugin. It is really nice to use.

    I have been searching on the developers manual but can’t see an answer to my question. I have a membership enabled called members with the subscriber user role and would like to have users automatically subscribed based on custom fields I have set up on the registration form.

    This is for a members organisation who would like to hide members resources to non members so on registration page I created I have a field which asks if they are a member or not. If yes then I would like them to be automatically subscribed to the membership I set up which allows access to the members resources.

    I am guessing it can be done with a simple function but am not much of a developer so not sure how to achieve it and would be grateful for any help you can offer.

    If you would rather I raised this as a support question I would be happy to do so.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Chad Butler

    (@cbutlerjr)

    You can use the wpmem_set_user_product() function in the api. Since you’re doing this at registration, you can set up a function to run hooked to wpmem_post_register_data (which is an action that comes after the user is created at registration).

    There’s an example of using the wpmem_set_user_product() function in this way in the documentation for the function:
    https://rocketgeek.com/plugins/wp-members/docs/api-functions/wpmem_set_user_product/

    You can expand on that and set any user product based on the criteria of whatever fields they are selecting in the registration form (getting the form data from either $_POST or what wpmem_post_register_data passes in the $fields array).

    Thread Starter fibiet

    (@fibiet)

    Thanks I’ll give it a try

    Thread Starter fibiet

    (@fibiet)

    Hi not sure I am understanding this right as I can’t seem to get it working.

    The field I want to trigger the membership being enabled is called are_you_a_gb_member and it is a No/Yes checkbox. The answer Yes triggering membership.

    The membership product I set up is called GB members (slug is gb-members).

    I set up the function like this trying to make sense of the two examples you gave

    add_action( ‘wpmem_post_register_data’, ‘my_reg_hook’ );
    function my_reg_hook( $fields ) {
    // Set my fields
    $meta = ‘are_you_a_gb_member’;
    $value = ‘yes’;
    $product_meta = ‘gb-member’;
    $user_id = $fields[‘ID’];
    // Set product access.
    wpmem_set_user_product( $product_meta, $user_id );
    return;
    }

    I don’t really quite get how it all works. Sorry to be so clueless.

    Thread Starter fibiet

    (@fibiet)

    Moving this to paid support as it feels like it is more appropriate there.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘automatic membership role based on user registration fields’ is closed to new replies.