Hi @gelieys
The solution is mostly working but am wondering if it is possible to send a default email template if a user role is not specified in the code snippet?
For example in the code below we are sending custom email templates to the ‘um_retailer’ and the ‘um_practitioner’ roles. Are we able to send a default template to all other roles not specified in the snippet? Or do we have to add all user roles to the snippet and specify the template they should use?
/**
* Send custom email templates (depending on UM user role) on UM User approve action.
* @param int $user_id User ID.
* @return boolean
*/
function custom_um_after_user_is_approved( $user_id = null ) {
if ( empty( $user_id ) ) {
$user_id = get_current_user_id();
}
$status = get_user_meta( $user_id, 'account_status', true );
if ( 'approved' !== $status ) {
return;
}
$rolename = UM()->roles()->get_priority_user_role( $user_id );
$userdata = get_userdata( $user_id );
switch ( $rolename ) {
case 'um_retailer':
UM()->mail()->send( $userdata->user_email, 'retailer_approved_email' );
break;
case 'um_practitioner':
UM()->mail()->send( $userdata->user_email, 'practitioner_approved_email' );
break;
default:
break;
}
}
add_action( 'um_after_user_is_approved', 'custom_um_after_user_is_approved' );