and is the message template : [user_type_text id="%recipient.id%" ]
Problem is : $atts[‘id’] is retrieved and is displayed, but never being passed to the get_userdata() function.
The return line displays : {}{114} and if 114 is hard-coded, it DOES return a user email.
The email is just an example here. I know I don’t need to retrieve it to send the email .
I spent some much time of this, trying to cast the variable (as here), using no quote, single quote, double quote for the param, using an intermediate variable to store the param. Also tried to pass the param as content of the shortcode : [myshortcode]someID[/myshortcode]
I also tried to do a simple sum as a return value return 2+intval($atts['id']); //always returns 2
So I am wondering if there is a limitation with this special tokens.
You can try to error_log(print_r($user_info, true)) to check why it’s empty, and if it’s an object at all. I recommend accessing properties via the token though, you can access the same fields as with the ID:
No need for a shortcode, let’s create my own token instead.
Basically, I have a custom attribute called ‘type’ (vendor / customer), and I wanted to display a different message according to this attribute.
add_filter(
'hivepress/v1/emails/message_send',
function( $email ) {
$email['tokens']['custom_msg_by_type'] = "";
//recipient is known, it's a hivepress User, let's get user meta from its ID.
$user_type = get_user_meta($email['tokens']['recipient']->get_id(), 'hp_type', true);
if($user_type==115){//freelance
$email['tokens']['custom_msg_by_type'] = "Hello Freelance!"; //or whatever
}else if($user_type==116){//customer
$email['tokens']['custom_msg_by_type'] = "Hello Customer!";
}
return $email;
}
);
in message email template : use %custom_msg_by_type% to display the message.