hi
thanks for the response.
btw im able to get the code :
function pmpro_after_change_membership_level($level_id, $user_id)
{
//get user object
$wp_user_object = new WP_User($user_id);
//ignore admins
if(in_array(“administrator”, $wp_user_object->roles))
return;
if($level_id == 4)
{
//New member of level #2. Give them Bronze role.
$wp_user_object->add_role(‘bronze_level’);
}
elseif($level_id == 3)
{
//New member of level #1. Give them Silver role.
$wp_user_object->add_role(‘silver_level’);
}
elseif($level_id == 2)
{
//New member of level #1. Give them Gold role.
$wp_user_object->add_role(‘gold_level’);
}
elseif($level_id == 5)
{
//New member of level #1. Give them Platinum role.
$wp_user_object->add_role(‘platinum_level’);
}
elseif( $level_id == 0 ) {
//Cancelling. Give them Subscriber role.
$wp_user_object->set_role(‘subscriber’);
}
}
add_action(‘pmpro_after_change_membership_level’, ‘pmpro_after_change_membership_level’, 10, 2);
i used add_role instead of set_role – it works perfectly of what i’ve wanted.
this way user assigned multiple roles.
however when cancelling one of the level,
e.g
bronze role cancelled it will set the roles back to subscriber & the other roles get removed.
is there a way only the bronze role will be removed and leave the other roles there ?