I made a plugin myself with a user-interface part, but additionally a cronjob that sends out emails on a daily basis. The user-interface part works fine multilingual, but I don't get the email-function properly multilingual.
Email sending is separate activity and my customers do not have a wordpress website account. I register them in a dedicated table (customers)
What does it look like:
function send_email($customers) {
foreach ($customers as $customer) {
/*.... do something to set the correct language from $customer->mylanguage; ......
$subject = __('This is the subject', 'wpml-text-file');
$content = __('content of my email', 'wpml-text-file');
$content .= __('second part of content of my email', 'wpml-text-file');
$sendTo = $customer->email;
$header = <...something.....>;
wpmail($sendTo, $subject, $content, $header);
}
}
I tried all solutions mentioned in the support documentation on https://wpml.org/documentation/support/sending-emails-with-wpml/ but unfortunately it did not work out. E.g. this solution, since the customers are not registered:
add_filter(‘wpml_user_language’, ‘my_recipients_language’, 10, 2);
function my_recipient_language($lang, $email) {
return get_language_from_my_database($email); // implement it in your plugin/theme
}
I located this at the start of my loop, but nothing changed...
So please, give me some advice or a working example.