Memberpress: cómo agregar usuarios a grupos al registrarse

I formatted your code so that it’s easier to see what’s going on.

$params['remove_groups] keeps getting redefined. As an example, if a user had been initially added to the ‘ForeverFree’ group on WordPress, and had then been removed from it, when the function is called for that user $params['remove_groups'] will first get set to ‘ForeverFree’, but in the next if statement it will get set to ‘CreativeLicense’… By the end of the function $params['remove_groups'] will probably have been set to ‘TransformPlus’.

There are a few ways you could approach this. We can’t get too into helping with PHP code on this forum, but you could try creating a $remove_groups variable that is an array:

$remove_groups = array();

and then in each if statment, add the group name to $remove_groups array:

	if ( current_user_can( 'mepr-active','memberships:47281' )  ) {
		$params['add_groups'] = 'ForeverFree';
	} else {
		$remove_groups[]  = 'ForeverFree'; // Adds the groupname to the array.
	}

	if ( current_user_can( 'mepr-active','memberships:47295,47297' )  ) {
		$params['add_groups'] = 'CreativeLicense';
	} else {
		$remove_groups[] = 'CreativeLicense';
	}

    // ...

At the end of the function, join the $remove_groups array with a comma and assign it to $params['remove_groups']

$params['remove_groups'] = join( ',', $remove_groups ); // Converts the array into a comma separated string.

If it’s possible for users to be added to more than one group at a time, you might need to take a similar approach with $params['add_groups'].

If you’re testing this with an admin user, I think that current_user_can( 'mepr-active', ... ) will always return true for an admin user. It’s something to watch out for.