Removing unwanted role after purchase

Just use $user->set_role( 'learner_member' ); instead of both lines where you are removing and adding the role.

Link to the docs.

File not found.