Skip to content Skip to sidebar

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client is experiencing an issue where email notifications sent from their multilingual e-commerce sites viviscal.bg and viviscal-store.com are displaying in multiple languages instead of just the language in which the order was made. This problem is linked to the YAY Mail plugin's handling of languages.
Solution:
We recommend updating the YAY Mail plugin's code to ensure that emails are sent in the correct language. Specifically, modify the

get_site_language

function in the WPMLIntegration.php file. Here's the step-by-step guide:

  1. Backup the original WPMLIntegration.php file located in /wp-content/plugins/yaymail-pro/includes/Integrations/Translations/.
  2. Replace the existing
    get_site_language

    function with the following code:

    public static function get_site_language( $order ) {
            global $sitepress;
            $language = \defined( 'ICL_LANGUAGE_CODE' ) ? ICL_LANGUAGE_CODE : 'en';
            if ( null !== $order || isset( $GLOBALS['yaymail_set_order'] ) ) {
                $order_data = ( null !== $order ) ? $order : $GLOBALS['yaymail_set_order'];
                // $order_language = $order_data->get_meta( 'wpml_language' );
                $post_language_details = apply_filters( 'wpml_post_language_details', null, $order_data->get_id() );
                $order_language        = isset( $post_language_details['language_code'] ) ? $post_language_details['language_code'] : '';
                if ( ! empty( $order_language ) ) {
                    $language = $order_language;
                }
            }
            $sitepress->switch_lang( $language );
            return $language;
        }

    with

    public static function get_site_language( $order ) {
        global $sitepress;
     
        // Use default language as safe fallback
        $language = apply_filters( 'wpml_default_language', null );
     
        if ( null !== $order || isset( $GLOBALS['yaymail_set_order'] ) ) {
            $order_data = ( null !== $order ) ? $order : $GLOBALS['yaymail_set_order'];
     
            $order_language = $order_data->get_meta( 'wpml_language', true );
     
            if ( ! empty( $order_language ) ) {
                $language = $order_language;
            }
        }
     
        do_action( 'wpml_switch_language', $language );
        return $language;
    }
  3. After updating the code, test the email notifications to ensure they are now sent in the correct language.

If this solution does not resolve your issue or seems irrelevant due to updates or different configurations, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the problem persists, please open a new support ticket.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Tagged: 

This topic contains 22 replies, has 0 voices.

Last updated by boyanK 6 months, 2 weeks ago.

Assisted by: Kor.

Author Posts
August 12, 2025 at 9:45 am #17312706

boyanK

Hello,
From our hosting support left the main domain to direct to Viviscal.bg. According to them, this is good for optimization. We don't like this solution either.

Use one of the subdomains to access the WordPress installation. Go to this link and work in Spanish or another language besides Bulgarian:
hidden link

August 13, 2025 at 3:47 pm #17318511

Kor

Thanks for your patience. I'm able to replicate the issue and I will escalate this to our 2nd Tier Support for further investigation. I will come back to you once I've feedback.

August 18, 2025 at 3:36 pm #17328462

Kor

Thanks for your patience. I have a feedback and this is what our 2nd Tier Support mentioned.

The problem is with the YAY Mail plugins. In the code in \YayMail\Integrations\Translations\WPMLIntegration::get_site_language in /wp-content/plugins/yaymail-pro/includes/Integrations/Translations/WPMLIntegration.php

Please backup and replace

public static function get_site_language( $order ) {
		global $sitepress;
		$language = \defined( 'ICL_LANGUAGE_CODE' ) ? ICL_LANGUAGE_CODE : 'en';
		if ( null !== $order || isset( $GLOBALS['yaymail_set_order'] ) ) {
			$order_data = ( null !== $order ) ? $order : $GLOBALS['yaymail_set_order'];
			// $order_language = $order_data->get_meta( 'wpml_language' );
			$post_language_details = apply_filters( 'wpml_post_language_details', null, $order_data->get_id() );
			$order_language        = isset( $post_language_details['language_code'] ) ? $post_language_details['language_code'] : '';
			if ( ! empty( $order_language ) ) {
				$language = $order_language;
			}
		}
		$sitepress->switch_lang( $language );
		return $language;
	}

with

public static function get_site_language( $order ) {
	global $sitepress;

	// Use default language as safe fallback
	$language = apply_filters( 'wpml_default_language', null );

	if ( null !== $order || isset( $GLOBALS['yaymail_set_order'] ) ) {
		$order_data = ( null !== $order ) ? $order : $GLOBALS['yaymail_set_order'];

		$order_language = $order_data->get_meta( 'wpml_language', true );

		if ( ! empty( $order_language ) ) {
			$language = $order_language;
		}
	}

	do_action( 'wpml_switch_language', $language );
	return $language;
}

Once you've done that, recheck the email notification and let us know how it goes.

August 19, 2025 at 8:03 am #17330099

boyanK

Hello

We have backup, please replace the code. I am not able to do it. Thank you!

August 19, 2025 at 8:10 am #17330112

Kor

Thanks for your reply. I've made the changes for you and could you please test now?

August 19, 2025 at 12:47 pm #17331350

boyanK

Hello
We checked, it looks ok. We will make few more tests. Only the string "Here’s a reminder of what you’ve ordered:" haven't been translated. I fixed it manually.

August 19, 2025 at 3:26 pm #17332052

Kor

Thanks for your reply. Glad that everything is working fine now. If you need anything further, you can let me know.

August 20, 2025 at 9:39 am #17333580

boyanK

Hello,
Thank you! It looks great!

August 20, 2025 at 9:40 am #17333581

boyanK

Very good work !