�PNG  IHDR22?�� pHYs  �� OiCCPPhotoshop ICC profilexڝSgTS�=���BK���KoR RB���&*! J�!��Q�EEȠ�����Q, � ��!���������{�kּ������>���� �H3Q5� �B�������.@� $p�d!s�#�~<<+"��x� �M��0���B�\���t�8K�@z�B�@F���&S�`�cb�P-`'������{[�!�� e�Dh;��V�EX0fK�9�-0IWfH���� � 0Q��){`�##x��F�W<�+��*x��<�$9E�[-qWW.(�I+6aa�@.�y�2�4���������x����6��_-��"bb���ϫp@�t~��,/��;�m��%�h^ �u��f�@����W�p�~<�5�j>{�-�]c�K'Xt����o��(�h���w��?�G�%�fI�q^D$.Tʳ?�D��*�A��,���� �`6�B$��BB d�r`)��B(�Ͱ*`/�@4�Qh��p.�U�=p�a��(�� A�a!ڈb�X#����!�H�$ ɈQ"K�5H1R�T UH�=r9�\F��;�2����G1���Q=� �C��7�F� �dt1�����r�=�6��Ыhڏ>C�0��3�l0.��B�8, �c˱"� ���V����cϱw�E� 6wB aAHXLXN�H� $4� 7 �Q�'"��K�&���b21�XH,#��/{�C�7$�C2'��I��T��F�nR#�,��4H#���dk�9�, +ȅ����3��!�[ �b@q��S�(R�jJ��4�e�2AU��Rݨ�T5�ZB���R�Q��4u�9̓IK�����hh�i��t�ݕN��W���G���w ��Ljg(�gw��L�Ӌ�T071���oUX*�*|�� �J�&�*/T����ު U�U�T��^S}�FU3S� Ԗ�U��P�SSg�;���g�oT?�~Y��Y�L�OC�Q��_�� c�x,!k ��u�5�&���|v*�����=���9C3J3W�R�f?�q��tN �(���~���)�)�4L�1e\k����X�H�Q�G�6������E�Y��A�J'\'Gg����S�Sݧ �M=:��.�k���Dw�n��^��Lo��y���}/�T�m���G X� $� �<�5qo</���QC]�@C�a�a�ᄑ��<��F�F�i�\�$�m�mƣ&&!&KM�M�RM��)�;L;L���͢�֙5�=1�2��כ߷`ZxZ,����eI��Z�Yn�Z9Y�XUZ]�F���%ֻ�����N�N���gð�ɶ�����ۮ�m�}agbg�Ů��}�}��= ���Z~s�r:V:ޚΜ�?}����/gX���3��)�i�S��Ggg�s�󈋉K��.�>.���Ƚ�Jt�q]�z���������ۯ�6�i�ܟ�4�)�Y3s���C�Q��? ��0k߬~OCO�g��#/c/�W�װ��w��a�>�>r��>�<7�2�Y_�7��ȷ�O�o�_��C#�d�z����%g��A�[��z|!��?:�e����A���AA�������!h�쐭!��Α�i�P~���a�a��~ '���W�?�p�X�1�5w��Cs�D�D�Dޛg1O9�-J5*>�.j<�7�4�?�.fY��X�XIlK9.*�6nl������� �{�/�]py�����.,:�@L�N8��A*��%�w%� y��g"/�6ш�C\*N�H*Mz�쑼5y$�3�,幄'���L Lݛ:��v m2=:�1����qB�!M��g�g�fvˬe����n��/��k���Y- �B��TZ(�*�geWf�͉�9���+��̳�ې7�����ᒶ��KW-X潬j9�������(�x��oʿ�ܔ���Ĺd�f�f���-�[����n �ڴ �V����E�/��(ۻ��C���<��e����;?T�T�T�T6��ݵa��n��{��4���[���>ɾ�UUM�f�e�I���?�������m]�Nmq����#�׹���=TR��+�G�����w- 6 U����#pDy��� �� :�v�{���vg/jB��F�S��[b[�O�>����z�G��499�?r����C�d�&����ˮ/~�����јѡ�򗓿m|������������x31^�V���w�w��O�| (�h���SЧ��������c3-� cHRMz%������u0�`:�o�_�F5IDATx��ytUս�?�;���fN$$��@B�!�k��� -*�gE���j�O�kQ�ʠ`U�B_ �AÐ0%�Ȕ�@r3ޛ;߳��$�@��v����^�s����������$��ߢ !�W��5�̱'-٘������4�>�Rƫ$�G��0U�H}�_ _� #��k�MJ/=�9Du *ڲ�k�PQ;0��j|�*�$�^컂脛y���>�z×� B��� ��(�:$�ʔ_�6��C!B����MVx��a��ζyY����j��ƋY2�9�F�{r��r�딟F��Q��hY6��� x��[l��RC��������nt@��;P��3��� F�w��7��:�P���ɋ'���mj���Bƪ�$�Q�L��y��߷g��\���z����v5�p�v$�v櫻�`6~K �Y�X����,�:��"�o�e0II"(��,������l_�C���/4�+f�E�!q��:����u����c��樼.UE�@� �]K�W���$-�h]�JG���Dz)�`��.�A/ ���mᏣc�3jK� �!�>���$�Q�!�_�? \�C2(E �M$Z I{�U���s�ǣ���=��@Բe ޻��W�����@ �w����}�9v,)��.}*|"�s��di���,���G�]W�AC�������|<����[��ߕ������K�*�G nߴ!��‹��J�!��6(L�a)��Am��������;adf��:�xm��nh�;֦I��(���o�C~ډa?�=��s����h��E������xp����)���_���t��W�����´;8���`dz=(��@@�+,�;�`�fhl��XȌ�3,uI�~z(J����� �ZX�A����H'�À�㜦�82|��a�n�z2��I���� ���EY�h�ε<�0�q�{��C��v�˅��?"@��χ�x�WS+��N�~�KQ�J�8ل�� _.W��� !TU{�����,��"�� �;�������HI S� ��))�o�1�H�D� ���� (� ;����"Ҕ��,���� �F=���O��&�Ph>�`���y��߲ &S��P�<��'��1s�1cĂ�N����2)����@�u��tv��<�+�-&�����h��[!FSG���' � z z0��<����8d&�����E0�,��<��"!P�b4��� �{S�����X����.�囤���T��hEF��X�q0"-<����h���]�Py*����F⩍��@v�˂�Y08�� .q��a��s����(!<̫1�3�L�H��7sYW�`��qtu�\7��?�@�Y�� %Ka�x�GZ�*W�P��y�����N0r9��Z�c�%���q,��k�����!!,��>���IB��� �x1�Xu�Y���v-���ֺ��N������JP��a�2`�e5��w��u;�6�i���̃��(K���ťa��(l51��JL��O'%���]���ٖ뿉!��{*�p+f ���i8��D�ȑ���ܩ�M��V��ӟz��x�7Z�1i}�^͜���6e����x��)u�d�ˏ�V�eG�\�X1�����=n�U'�~Y����L�\,�(d!x ,�:�TW8� M`r���@��r+v�Q0��>^;˴�VbF��('����� �*O��i��j�Ӆ����^�S3&� ���{������.ی�� N;��NU%d0�Ce\r"�C�b��&t7N�7��� �ȪD�[%l�۪�$��'m?�A9tI�9>��NVL ��� 6v~M�����ъ�B���0����9$&=ώm��W�0���L���&��E���f�f��'+�9��hv��7,���M��6�D�&�^� �����8 D֮�����o��k^z��O��hP�8q�5d*��YVq3�{��������#LX4�?��jP=3�~�؅c�ݰ�̱�ұ��8̲��2�G�����j��έ�9��w7���U�X�w�85C��?!I&���o&����L���I#�^�eV�,�^t5�k� �xs˛\��U�8��."���{���ǵ�l4��ݼ�;��r"���G�/~���gJV�N糦��ZZ^k+NN�D��I$�=OE�z����|*�*{��%k���G��>�`9��b;�s���8,�qs��c��.b��q�%�>r��n�R�Ƨ�%�,�A��le#�8���}; 21�0�b�&�QX�f���q�00����$>�h�N�'�a3��A���/�r ��L5�8�GԲ'�����w;��c#�q1���h$*��V^�k��QĽ�b:i������� ����H F#�_���,��]g����Ը����`RUU���� ��"�qD���>-��ϤI�~��3�̴�����NZ[[555�eeek7�m����YF#[��Đ��R��i��L�H�r ��@��J-�Pŝ��_|�-��6y��ks�V�U~��6���w.����(��0A� 4��f��� /���C�xŊ�ٳ����z=6�����rg���mKo��o�/����a�g���?'9%9��P��斓��~���L{�� �H��{AW��B��$����v�1b�&Mb�ر��ر#�0`�`xMBp! )Z�Nmo�mZ�g�}�eذaWTVV ���'99��C5��&�&+5�bT>|8��PUUETT����&���t��~TE%��'������b�tEGG;RSS�S�N�v��ѯ��t����u1@�ޚ"f��͈���r'L�Ph��m��ƌ�74o��`�x�q�P���NRSS�X,�����l&&&��MFFA!-��`��ҷ�n��Yuu�����x<I�LB%����KԒ50�!�3�bz�����ʸKL���;---�l6[��`��������Ȏ;�����egg4��!D�T��jWujyZ��������K����%����p�^���X,6��sV=�ܖ����6�3�X ���4ҿ��A2�&����_k�;d�� �VfOIEND�B`�
Warning: session_start(): Session cannot be started after headers have already been sent in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 124

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 130

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 131

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 132

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 133

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 134

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 135
0x0x
PHP 8.2.31
Preview: emails.php Size: 16.93 KB
/home/mciraet/www/wp-content/plugins/polylang-wc/src/emails.php
<?php
/**
 * @package Polylang-WC
 */

/**
 * Associates a language to the user and to orders and manages the customer emails languages.
 *
 * @since 0.1
 */
class PLLWC_Emails {
	/**
	 * Product language data store.
	 *
	 * @var PLLWC_Order_Language_CPT
	 */
	protected $data_store;

	/**
	 * Stores previous language information each time it may be switched.
	 *
	 * @var array[] {
	 *   @type bool              $switched Has the WordPress locale been switched?
	 *   @type PLL_Language|null $language Previous current language.
	 * }
	 *
	 * @phpstan-var array<array{switched:bool, language:PLL_Language|null}>
	 */
	private $previous_languages = array();

	/**
	 * Constructor.
	 *
	 * Setups filters and actions.
	 *
	 * @since 0.1
	 */
	public function __construct() {
		$this->data_store = PLLWC_Data_Store::load( 'order_language' );

		add_action( 'change_locale', array( $this, 'change_locale' ), 1 ); // Soon to load the plugin_locale filter.

		// Deactivate the email locale switch from WooCommerce.
		add_filter( 'woocommerce_email_setup_locale', '__return_false' );
		add_filter( 'woocommerce_email_restore_locale', '__return_false' );

		// Define the customer preferred language.
		add_action( 'woocommerce_created_customer', array( $this, 'created_customer' ), 5 ); // Before WC sends the notification.
		add_action( 'woocommerce_new_order', array( $this, 'new_order' ) );

		// Manually sent order emails from order action metabox.
		add_action( 'woocommerce_before_resend_order_emails', array( $this, 'resend_order_email' ), 10, 2 );
		add_action( 'woocommerce_after_resend_order_email', array( $this, 'after_email' ) );

		// Translate site title.
		add_filter( 'woocommerce_email_format_string_replace', array( $this, 'format_string_replace' ), 10, 2 );

		// Delays the the addition of other actions after WC_Emails init.
		add_action( 'woocommerce_email', array( $this, 'mailer_init' ) );

		if ( is_user_logged_in() ) {
			// Sets the email language for previewed emails in the admin. Useful when displaying and sending the previewed emails.
			add_filter( 'woocommerce_prepare_email_for_preview', array( $this, 'set_previewed_email_language' ) );
		}
	}

	/**
	 * Sets the email language for previewed emails.
	 * The goal is to translate the previewed email strings when rendering and sending the previewed email.
	 *
	 * @since 2.2
	 *
	 * @param WC_Email $email The email object. Unused.
	 * @return WC_Email
	 */
	public function set_previewed_email_language( $email ) {
		$language = PLL()->model->get_language( get_locale() );

		if ( empty( $language ) ) {
			return $email;
		}

		$this->set_email_language( $language );

		return $email;
	}


	/**
	 * Setups actions related to automatically sent emails.
	 *
	 * This is delayed after the first call to WC()->mailer() to avoid setting up
	 * emails sooner than expected.
	 *
	 * @since 1.6.3
	 *
	 * @param WC_Emails $mailer The WooCommerce emails controller.
	 * @return void
	 */
	public function mailer_init( $mailer ) {
		$this->user_emails_init();
		$this->customer_emails_init();

		/**
		 * Filters if the emails sent to shop managers must be sent in their own language.
		 *
		 * @since 1.7
		 *
		 * @param bool $enable True if emails are sent in shop manager language, false otherwise.
		 */
		if ( apply_filters( 'pllwc_enable_shop_manager_email_language', true ) ) {
			$this->shop_manager_emails_init( $mailer );
		}
	}

	/**
	 * Setups actions related to emails sent to a user.
	 *
	 * @since 1.7
	 *
	 * @return void
	 */
	protected function user_emails_init() {
		/**
		 * Filters the actions used to send translated emails to a user.
		 * The actions in the list must pass a `WP_User` or user id as first parameter.
		 *
		 * @since 1.6
		 *
		 * @param string[] $email_actions Array of actions used to send user emails.
		 */
		$actions = apply_filters(
			'pllwc_user_email_actions',
			array(
				'woocommerce_created_customer_notification', // Customer new account.
				'woocommerce_reset_password_notification', // Reset password.
			)
		);

		foreach ( $actions as $action ) {
			add_action( $action, array( $this, 'before_user_email' ), 1 ); // Switch the language for the email.
			add_action( $action, array( $this, 'after_email' ), 999 ); // Switch the language back after the email has been sent.
		}
	}

	/**
	 * Setups actions related to emails sent to a customer.
	 *
	 * @since 1.7
	 *
	 * @return void
	 */
	protected function customer_emails_init() {
		/**
		 * Filters the actions used to send translated customer emails related to an order.
		 * The actions in the list must pass a `WC_Order` or order id as first parameter.
		 *
		 * @since 1.6
		 *
		 * @param string[] $email_actions Array of actions used to send order emails.
		 */
		$actions = apply_filters(
			'pllwc_order_email_actions',
			array(
				// Completed order.
				'woocommerce_order_status_completed_notification',
				// Customer note.
				'woocommerce_new_customer_note_notification',
				// On hold.
				'woocommerce_order_status_failed_to_on-hold_notification',
				'woocommerce_order_status_pending_to_on-hold_notification',
				'woocommerce_order_status_cancelled_to_on-hold_notification',
				// Processing.
				'woocommerce_order_status_cancelled_to_processing_notification',
				'woocommerce_order_status_failed_to_processing_notification',
				'woocommerce_order_status_on-hold_to_processing_notification',
				'woocommerce_order_status_pending_to_processing_notification',
				// Refunded order.
				'woocommerce_order_fully_refunded_notification',
				'woocommerce_order_partially_refunded_notification',
			)
		);

		foreach ( $actions as $action ) {
			add_action( $action, array( $this, 'before_order_email' ), 1 ); // Switch the language for the email.
			add_action( $action, array( $this, 'after_email' ), 999 ); // Switch the language back after the email has been sent.
		}
	}

	/**
	 * Setups actions related to emails sent to shop managers.
	 *
	 * @since 1.7
	 *
	 * @param WC_Emails $mailer The WooCommerce emails controller.
	 * @return void
	 */
	protected function shop_manager_emails_init( $mailer ) {
		if ( empty( $mailer->emails ) ) {
			return;
		}

		// Define email types and their corresponding actions.
		$email_config = array(
			'WC_Email_Cancelled_Order' => array(
				'actions'  => array( // Cancelled order emails sent to shop managers.
					'woocommerce_order_status_processing_to_cancelled_notification',
					'woocommerce_order_status_on-hold_to_cancelled_notification',
				),
				'callback' => 'send_cancelled_order_email',
			),
			'WC_Email_Failed_Order'    => array(
				'actions'  => array( // Failed order emails sent to shop managers.
					'woocommerce_order_status_pending_to_failed_notification',
					'woocommerce_order_status_on-hold_to_failed_notification',
				),
				'callback' => 'send_failed_order_email',
			),
			'WC_Email_New_Order'       => array(
				'actions'  => array( // New order emails sent to shop managers.
					'woocommerce_order_status_pending_to_processing_notification',
					'woocommerce_order_status_pending_to_completed_notification',
					'woocommerce_order_status_pending_to_on-hold_notification',
					'woocommerce_order_status_failed_to_processing_notification',
					'woocommerce_order_status_failed_to_completed_notification',
					'woocommerce_order_status_failed_to_on-hold_notification',
					'woocommerce_order_status_cancelled_to_processing_notification',
					'woocommerce_order_status_cancelled_to_completed_notification',
					'woocommerce_order_status_cancelled_to_on-hold_notification',
				),
				'callback' => 'send_new_order_email',
			),
		);

		// Process each email type.
		foreach ( $email_config as $email_class => $config ) {
			if ( ! isset( $mailer->emails[ $email_class ] ) ) {
				continue;
			}

			$email = $mailer->emails[ $email_class ];
			foreach ( $config['actions'] as $action ) {
				remove_action( $action, array( $email, 'trigger' ) );
				add_action( $action, array( $this, $config['callback'] ) );
			}
		}
	}

	/**
	 * Set the preferred customer language at customer creation.
	 * Hooked to the action 'woocommerce_created_customer'.
	 *
	 * @since 0.1
	 *
	 * @param int $user_id User ID.
	 * @return void
	 */
	public function created_customer( $user_id ) {
		update_user_meta( $user_id, 'locale', get_locale() );
	}

	/**
	 * Maybe changes the customer language when he places a new order.
	 * The chosen language is the currently browsed language.
	 * Hooked to the action 'woocommerce_new_order'.
	 *
	 * @since 1.0
	 *
	 * @param int $order_id Order ID.
	 * @return void
	 */
	public function new_order( $order_id ) {
		if ( PLL() instanceof PLL_Frontend ) {
			$order = wc_get_order( $order_id );
			if ( $order instanceof WC_Order ) {
				$user_id = $order->get_user_id();
				if ( $user_id ) {
					$order_locale = $this->data_store->get_language( $order_id, 'locale' );
					$user_locale  = get_user_meta( $user_id, 'locale', true );
					if ( ! empty( $order_locale ) && $order_locale !== $user_locale ) {
						update_user_meta( $user_id, 'locale', $order_locale );
					}
				}
			}
		}
	}

	/**
	 * Loads the WooCommerce text domain when the locale is switched.
	 * Hooked to the action 'change_locale'.
	 *
	 * @since 1.0.2
	 *
	 * @return void
	 */
	public function change_locale() {
		if ( is_locale_switched() ) {
			if ( isset( PLL()->filters ) ) {
				remove_filter( 'locale', array( PLL()->filters, 'get_locale' ) );
				remove_filter( 'load_textdomain_mofile', array( PLL()->filters, 'load_textdomain_mofile' ) );
			}
			add_filter( 'get_user_metadata', array( $this, 'filter_user_locale' ), 10, 3 );
		} else {
			if ( PLL() instanceof PLL_Frontend && isset( PLL()->filters ) ) {
				add_filter( 'locale', array( PLL()->filters, 'get_locale' ) );
			}
			remove_filter( 'get_user_metadata', array( $this, 'filter_user_locale' ) );
		}

		if ( version_compare( $GLOBALS['wp_version'], '6.7-beta', '<' ) && method_exists( WC(), 'load_plugin_textdomain' ) ) {
			// Backward compatibility with WP < 6.7.
			WC()->load_plugin_textdomain();
		}
	}

	/**
	 * Sets the email language.
	 *
	 * @since 0.1
	 *
	 * @param PLL_Language $language An instance of PLL_Language.
	 * @return void
	 */
	public function set_email_language( $language ) {
		$this->previous_languages[] = array(
			'switched' => switch_to_locale( $language->locale ),
			'language' => empty( PLL()->curlang ) ? null : PLL()->curlang,
		);

		PLL()->curlang = $language;

		PLLWC_Filter_WC_Pages::init();

		if ( ! is_locale_switched() ) {
			PLL()->load_strings_translations( $language->get_locale() );
		}

		/**
		 * Fires just after the language of the email has been set.
		 *
		 * @since 0.1
		 */
		do_action( 'pllwc_email_language' );
	}

	/**
	 * Sets the email language depending on the order language.
	 * Hooked to order notifications.
	 *
	 * @since  0.1
	 *
	 * @param int|array|WC_Order $order Order or order ID.
	 * @return void
	 */
	public function before_order_email( $order ) {
		if ( is_numeric( $order ) ) {
			$order_id = $order;
		} elseif ( is_array( $order ) ) {
			$order_id = $order['order_id'];
		} elseif ( is_object( $order ) ) {
			$order_id = $order->get_id();
		}

		if ( ! empty( $order_id ) ) {
			$lang = $this->data_store->get_language( $order_id );
			$language = PLL()->model->get_language( $lang );
			if ( $language ) {
				$this->set_email_language( $language );
			}
		}
	}

	/**
	 * Sets the email language depending on the user language.
	 * Hooked to user notifications.
	 *
	 * @since 0.1
	 *
	 * @param int|string $user User ID or user login.
	 * @return void
	 */
	public function before_user_email( $user ) {
		if ( is_numeric( $user ) ) {
			$user_id = (int) $user;
		} else {
			$user = get_user_by( 'login', $user );
			if ( $user instanceof WP_User ) {
				$user_id = $user->ID;
			}
		}

		if ( isset( $user_id ) ) {
			$lang = get_user_meta( $user_id, 'locale', true );
			$lang = empty( $lang ) ? get_locale() : $lang;
			$language = PLL()->model->get_language( $lang );
			if ( $language ) {
				$this->set_email_language( $language );
			}
		}
	}

	/**
	 * Restores the current language after the email has been sent.
	 * Hooked to order and user notifications.
	 *
	 * @since 0.1
	 *
	 * @return void
	 */
	public function after_email() {
		if ( empty( $this->previous_languages ) ) {
			return;
		}

		$previous = array_pop( $this->previous_languages );

		if ( $previous['switched'] ) {
			restore_previous_locale();
		}

		PLL()->curlang = $previous['language'];
	}

	/**
	 * Translate the site title which is filled before the email is triggered.
	 * Hooked to the filter 'woocommerce_email_format_string_replace'.
	 *
	 * @since 0.5
	 *
	 * @param string[] $replace Array of strings to replace placeholders in emails.
	 * @param WC_Email $email   Instance of WC_Email.
	 * @return string[]
	 */
	public function format_string_replace( $replace, $email ) {
		$replace['blogname']   = $email->get_blogname();
		$replace['site-title'] = $email->get_blogname();
		// Ensures the date format is used in the correct language for previewed emails.
		if ( $email->object instanceof WC_Order ) {
			$order_date = $email->object->get_date_created();
			if ( ! empty( $order_date ) ) {
				$replace['order-date'] = wc_format_datetime( $order_date );
			}
		}
		return $replace;
	}

	/**
	 * Filters the user locale. Needed when sending the email from admin.
	 *
	 * @since 1.0.3
	 *
	 * @param mixed  $value    The value get_metadata() should return.
	 * @param int    $user_id  User ID.
	 * @param string $meta_key Meta key.
	 * @return mixed The meta value.
	 */
	public function filter_user_locale( $value, $user_id, $meta_key ) {
		return 'locale' === $meta_key ? get_locale() : $value;
	}

	/**
	 * Get the user language by email.
	 *
	 * @nince 1.6
	 *
	 * @param string $email Email.
	 * @return PLL_Language The language of the user having this email, the default language if not found.
	 */
	protected function get_language_by_email( $email ) {
		$user = get_user_by( 'email', $email );

		if ( $user instanceof WP_User ) {
			$locale = get_user_meta( $user->ID, 'locale', true );
			$language = PLL()->model->get_language( $locale );
		}

		if ( empty( $language ) ) {
			// In the eventuality that the user locale is not part of a Polylang language.
			$language = pll_default_language( 'OBJECT' );
		}

		return $language;
	}

	/**
	 * Sends order email in the user's language.
	 *
	 * @since 1.6
	 *
	 * @param WC_Email $email    WooCommerce Email Class.
	 * @param int      $order_id Order id.
	 * @return void
	 */
	protected function send_order_email( $email, $order_id ) {
		if ( method_exists( $email, 'trigger' ) ) {
			$recipients = $this->get_recipients( $email );

			remove_filter( 'get_user_metadata', array( $this, 'filter_user_locale' ) );

			$emails_by_language = array();

			foreach ( $recipients as $recipient ) {
				$language = $this->get_language_by_email( $recipient );
				$emails_by_language[ $language->slug ]['language']     = $language;
				$emails_by_language[ $language->slug ]['recipients'][] = $recipient;
			}

			foreach ( $emails_by_language as $em ) {
				$this->set_email_language( $em['language'] );
				$email->recipient = implode( ',', $em['recipients'] );
				$email->trigger( $order_id );
				$this->after_email();
			}
		}
	}

	/**
	 * Sends cancelled order email in the user's language.
	 *
	 * @since 1.6
	 *
	 * @param int $order_id Order id.
	 * @return void
	 */
	public function send_cancelled_order_email( $order_id ) {
		$this->send_order_email( WC()->mailer()->emails['WC_Email_Cancelled_Order'], $order_id );
	}

	/**
	 * Sends failed order email in the user's language.
	 *
	 * @since 1.6
	 *
	 * @param int $order_id Order id.
	 * @return void
	 */
	public function send_failed_order_email( $order_id ) {
		$this->send_order_email( WC()->mailer()->emails['WC_Email_Failed_Order'], $order_id );
	}

	/**
	 * Sends new order email in the user's language.
	 *
	 * @since 1.6
	 *
	 * @param int $order_id Order id.
	 * @return void
	 */
	public function send_new_order_email( $order_id ) {
		add_filter( 'woocommerce_new_order_email_allows_resend', '__return_true' );
		$this->send_order_email( WC()->mailer()->emails['WC_Email_New_Order'], $order_id );
	}

	/**
	 * Handles emails sent from the order actions metabox.
	 *
	 * @since 1.6
	 *
	 * @param WC_Order $order  Order.
	 * @param string   $action Order action.
	 * @return void
	 */
	public function resend_order_email( $order, $action ) {
		if ( 'new_order' === $action ) {
			$this->send_new_order_email( $order->get_id() ); // Send email in the user's language.
			add_filter( 'woocommerce_email_enabled_new_order', '__return_false' ); // Prevents WC to resend the email.
		} else {
			$this->before_order_email( $order ); // Other emails are sent to the customer in the order's language.
		}
	}

	/**
	 * Returns an array of recipients for the given email type.
	 *
	 * @since 1.8
	 *
	 * @param WC_Email $email Email object.
	 * @return string[] Array of recipients for the email.
	 */
	protected function get_recipients( $email ) {
		$recipients = $email->get_option( 'recipient', get_option( 'admin_email' ) );
		$recipients = explode( ',', $recipients );
		$recipients = array_map( 'trim', $recipients );
		return array_filter( $recipients );
	}
}

Directory Contents

Dirs: 6 × Files: 26
Name Size Perms Modified Actions
admin DIR
- drwxr-xr-x 2026-08-16 07:29:59
Edit Download
Cart DIR
- drwxr-xr-x 2026-08-16 07:29:59
Edit Download
frontend DIR
- drwxr-xr-x 2026-08-16 07:29:59
Edit Download
legacy DIR
- drwxr-xr-x 2026-08-16 07:29:59
Edit Download
modules DIR
- drwxr-xr-x 2026-08-16 07:29:59
Edit Download
plugins DIR
- drwxr-xr-x 2026-08-16 07:29:59
Edit Download
1.38 KB lrw-r--r-- 2026-06-02 10:19:43
Edit Download
1.97 KB lrw-r--r-- 2026-06-02 10:19:43
Edit Download
1.60 KB lrw-r--r-- 2026-06-02 10:19:43
Edit Download
16.93 KB lrw-r--r-- 2026-06-02 10:19:43
Edit Download
1.54 KB lrw-r--r-- 2026-06-02 10:19:43
Edit Download
710 B lrw-r--r-- 2026-06-02 10:19:43
Edit Download
2.09 KB lrw-r--r-- 2026-06-02 10:19:43
Edit Download
4.11 KB lrw-r--r-- 2026-06-02 10:19:43
Edit Download
8.68 KB lrw-r--r-- 2026-06-02 10:19:43
Edit Download
3.01 KB lrw-r--r-- 2026-06-02 10:19:43
Edit Download
6.83 KB lrw-r--r-- 2026-06-02 10:19:43
Edit Download
13.04 KB lrw-r--r-- 2026-06-02 10:19:43
Edit Download
4.32 KB lrw-r--r-- 2026-06-02 10:19:43
Edit Download
2.62 KB lrw-r--r-- 2026-06-02 10:19:43
Edit Download
3.69 KB lrw-r--r-- 2026-06-02 10:19:43
Edit Download
557 B lrw-r--r-- 2026-06-02 10:19:43
Edit Download
20.25 KB lrw-r--r-- 2026-06-02 10:19:43
Edit Download
25.59 KB lrw-r--r-- 2026-06-02 10:19:43
Edit Download
2.73 KB lrw-r--r-- 2026-06-02 10:19:43
Edit Download
7.32 KB lrw-r--r-- 2026-06-02 10:19:43
Edit Download
20.92 KB lrw-r--r-- 2026-06-02 10:19:43
Edit Download
6.22 KB lrw-r--r-- 2026-06-02 10:19:43
Edit Download
2.36 KB lrw-r--r-- 2026-06-02 10:19:43
Edit Download
6.71 KB lrw-r--r-- 2026-06-02 10:19:43
Edit Download
1.53 KB lrw-r--r-- 2026-06-02 10:19:43
Edit Download
3.44 KB lrw-r--r-- 2026-06-02 10:19:43
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).
© 2026 0xNothings — Secure File Manager. All rights reserved. Built with ❤️ & Tailwind x Dark UI