Give all new registered users a specific membership automaticlly

Hey! Is it possible to automaticlly give all new registered users a specific membership without any signup? Like, if someone register in my wp form they gets the membership "trial" without doing anything.

Cheers, Marcus

  • Adam Czajczyk

    Hello Marcus,

    I hope you're well today and thank you for your question!

    This should be possible with a little piece of additional 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();
    
    }

    In order to apply it to your site please create an empty file with a .php extension, paste the code there and upload it to the "/wp-content/mu-plugins" folder on your server. If there's no "mu-plugins" folder inside "wp-content" folder, just create it.

    Don't forget to replace the number in this line with a real ID of your selected membership :slight_smile:

    $membership_id = 1343;

    Best regards,
    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.