Different emails for different languages with WPML

For you to send personalized emails for each language after user registration, you’ll have to use a shortcode by installing a small plugin from: https://www.cozmoslabs.com/33775-wordpress-shortcode-compare-values/

NOTE: This doesn’t work with Email Confirmation.

That allows you send different information based on registration language. Before that there a few steps to follow:

  • In Profile Builder -> Manage Fields create a new custom field that has a type of Hidden Input, called ‘wpml_client_lang’ and make sure it’s got the same meta_name
  • Create an empty plugin like this: https://gist.github.com/sareiodata/76f701e01db6685829db
  • Add the following code to the end of it:
  • 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    
    /*
     * WPML save client language on registration.
     */
     
    /* handle field save */
    function wppbc_wpml_client_language( $field, $user_id, $request_data, $form_location ){
        if( defined( 'ICL_LANGUAGE_CODE' )) {
            $current_lang = ICL_LANGUAGE_CODE;
        } else {
            $current_lang = '';
        }
     
        if( $field['field'] == 'Input (Hidden)' && $field['meta-name'] == 'wpml_client_lang' ){
            if ( isset( $request_data[wppb_handle_meta_name( $field['meta-name'] )] ) )
                update_user_meta( $user_id, $field['meta-name'], $current_lang );
        }
    }
    add_action( 'wppb_save_form_field', 'wppbc_wpml_client_language', 20, 4 );
  • Install this plugin via FTP (copy it inside wp-content/plugins) or create a zip archive with it and install it via the WordPress plugin upload functionality. Then activate it.

Go to Profile Builder -> User Email Customizer and modify the template you’re interested in to something similar to:

1
2
3
4
5
6
7
8
9
[compare val1="{{wpml_client_lang}}" val2="en" operator="=="]
<h3>Welcome to {{site_name}}!</h3>
<p>Your username is:{{username}}</p>
[/compare]
 
[compare val1="{{wpml_client_lang}}" val2="ro" operator="=="]
<h3>Bine ati venit la {{site_name}}!</h3>
<p>Numele de utilizator este: {{username}}</p>
[/compare]

This works for both Admin and User Email Customizer.