• Resolved Ciao121

    (@ciao121)


    Hi,
    I’m using the plugin in a multil anguage WordPress site. I translated all outgoing mails.
    But when an admin confirms (or rejects) a reservation the email sent to the customer is sent in the language that the admin has set as his default language for the site. But the mail language should be the one used by the customer to make the reservation.
    Is this a missing feature or am I missing something?

    Thank you!

Viewing 10 replies - 1 through 10 (of 10 total)
  • Hi @ciao121,

    This is a limitation of the way that WPML implements it’s multi-language features. The language is always set by the current user, so when a user makes a booking, it is done in the language the current user has selected. But when the admin confirms the booking, WPML detects the current user’s language and runs off of that.

    WPML doesn’t know the language of the booking itself, only the language the current user has selected, so the notification emails are always sent in the language of the request which triggered that email.

    I usually advise restaurants to write their confirmation or rejection messages in all languages, so that whatever the language of the original booking, the customer will receive a message in their language.

    Thread Starter Ciao121

    (@ciao121)

    Thank you. This is what I’m doing now.
    If I find a workaround I’ll write it here.

    Thread Starter Ciao121

    (@ciao121)

    I think that WPML has this feature. Look here:
    https://wpml.org/documentation/support/sending-emails-with-wpml/

    On the same page:
    There is an example how to store user language when he’s not a registered user

    What you’re indicating isn’t really appropriate for this use-case, as the user is never really stored in the database.

    The main issue I face as a developer is that supporting this for WPML requires writing an implementation specifically for WPML. Since every multilingual plugin handles data differently, I’d need to also write implementations for other translation plugins (qTranslate, Babble, etc). It quickly becomes a lot of work to maintain that over time, and since I don’t have close control over these third-party plugins, it exposes the plugin to potential bugs down the line that are out of my control.

    For these reasons, I have so far stopped short of providing any more than the most basic support for WPML. But I may consider taking additional steps in the future if I get stronger demand.

    Thread Starter Ciao121

    (@ciao121)

    If I have correctly understood the page I linked above it is not needed to store the user in the database. It’s only needed to store the language he’s using when storing his email. So it can be retrieved later and passed to wpml functions. And having the languge stored can be usful not only for WPML.

    But it should already be a way to retrieve reservation language users (but I cannot find where). Because, as in my other post, in the reservation admin page I can switch between reservations made in different languages.

    Thread Starter Ciao121

    (@ciao121)

    I’ve found a solution; when the user submit the reservation form we can take the used language with this:

    if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
      $reservation_language=ICL_LANGUAGE_CODE;
    }

    If we append &lang=language code (i.e. &lang=$reservation_language) the the confirm or reject link template the sent confirm or reject mail will be sent in the user language.
    The admin should have the “Set admin language as editing language” option ON to make this work.

    Do you think this can be added by default to the plugin, or should I find my solution to add this in a way it stays in place after I update your plugin?

    Thank you!

    Hi @ciao121,

    That’s great to hear! Unfortunately, the &lang=<lang_code> will only work on the confirm or reject links in the emails. This won’t work if the booking is confirmed or rejected from the bookings list in the admin area.

    I was unable to find any documentation in WPML about the ICL_LANGUAGE_CODE constant. A bunch of forum posts pop up, but no official documentation. Have you found documentation about it somewhere?

    The key information I’m looking for is to determine under what conditions the ICL_LANGUAGE_CODE constant is defined and what language it is set to.

    The issue with this is that it only works on the request right when the booking is made. We need to be able to query the language of the original booking even when we’re viewing information about the booking in a completely separate request. WPML must have some way to do this since, as you said, you can switch between bookings made in different languages.

    It looks like this filter is what we need:

    https://wpml.org/wpml-hook/wpml_post_language_details/

    So we need to use that in combination some code to switch languages and thens switch back. Unfortunately, I’m really struggling to find any useful documentation from WPML about what seems like a very simple task. I will need to reach out to them to explore this further.

    Once we figure out that missing piece, though, you should be able to use the following hooks from my plugin to toggle the language before sending the notification emails:

    
    /**
     * Hook in before a notification is sent
     */
    add_action( 'rtb_send_notification_before', function( $notification ) {
    
    	// Don't do anything if this isn't an email notification
    	if ( !is_a( $notification, 'rtbNotificationEmail' ) ) {
    		return;
    	}
    
    	// Switch the language here
    
    	// Fetch the subject and message again
    	$notification->set_subject();
    	$notification->set_message();
    }
    
    /**
     * Hook in after a notification is sent
     */
    add_action( 'rtb_send_notification_after', function( $notification ) {
    
    	// Don't do anything if this isn't an email notification
    	if ( !is_a( $notification, 'rtbNotificationEmail' ) ) {
    		return;
    	}
    
    	// Switch the language back to what it was before
    
    }
    

    Hi @natewr

    I have the same problem.

    I don’t understand the last solution

    Once we figure out that missing piece, though, you should be able to use the following hooks from my plugin to toggle the language before sending the notification emails:

    /**
    * Hook in before a notification is sent
    */
    add_action( ‘rtb_send_notification_before’, function( $notification ) {

    // Don’t do anything if this isn’t an email notification
    if ( !is_a( $notification, ‘rtbNotificationEmail’ ) ) {
    return;
    }

    // Switch the language here

    // Fetch the subject and message again
    $notification->set_subject();
    $notification->set_message();
    }

    /**
    * Hook in after a notification is sent
    */
    add_action( ‘rtb_send_notification_after’, function( $notification ) {

    // Don’t do anything if this isn’t an email notification
    if ( !is_a( $notification, ‘rtbNotificationEmail’ ) ) {
    return;
    }

    // Switch the language back to what it was before

    }

    Where I insert this code?

    Best regards
    Ricardo

    NateWr

    (@natewr)

    Hi Ricardo,

    This code is not yet working anyway. It needs further work to actually perform the language switch.

    When it’s complete, you could insert it in a number of places, depending on what’s easiest, such as a custom plugin or your theme’s functions.php file.

    I am also interested to follow this topic.
    And many thanks for a great plug in

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Multilanguage confirmation message’ is closed to new replies.