/inc/class-wcml-emails.php

  1. <?php 
  2. class WCML_Emails{ 
  3.  
  4. private $order_id = false; 
  5. private $locale = false; 
  6. private $woocommerce_wpml; 
  7. private $sitepress; 
  8.  
  9. function __construct( &$woocommerce_wpml, &$sitepress ) { 
  10. $this->woocommerce_wpml = $woocommerce_wpml; 
  11. $this->sitepress = $sitepress; 
  12. add_action( 'init', array( $this, 'init' ) ); 
  13.  
  14. function init() { 
  15. global $pagenow; 
  16. //wrappers for email's header 
  17. if(is_admin() && !defined( 'DOING_AJAX' )) { 
  18. add_action('woocommerce_order_status_completed_notification', array($this, 'email_heading_completed'), 9); 
  19. add_action('woocommerce_order_status_changed', array($this, 'comments_language'), 10); 
  20.  
  21. add_action('woocommerce_new_customer_note_notification', array($this, 'email_heading_note'), 9); 
  22. add_action('wp_ajax_woocommerce_mark_order_complete', array($this, 'email_refresh_in_ajax'), 9); 
  23.  
  24. add_action( 'woocommerce_order_status_pending_to_processing_notification', array( $this, 'email_heading_processing' ) ); 
  25. add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $this, 'email_heading_processing' ) ); 
  26.  
  27. //wrappers for email's body 
  28. add_action('woocommerce_before_resend_order_emails', array($this, 'email_header')); 
  29. add_action('woocommerce_after_resend_order_email', array($this, 'email_footer')); 
  30.  
  31. //filter string language before for emails 
  32. add_filter('icl_current_string_language', array($this, 'icl_current_string_language'), 10 , 2); 
  33.  
  34. //change order status 
  35. add_action('woocommerce_order_status_completed', array($this, 'refresh_email_lang_complete'), 9); 
  36. add_action('woocommerce_order_status_pending_to_processing_notification', array($this, 'refresh_email_lang'), 9); 
  37. add_action('woocommerce_order_status_pending_to_on-hold_notification', array($this, 'refresh_email_lang'), 9); 
  38. add_action('woocommerce_new_customer_note', array($this, 'refresh_email_lang'), 9); 
  39.  
  40.  
  41. add_action('woocommerce_order_partially_refunded_notification', array($this, 'email_heading_refund'), 9); 
  42. add_action('woocommerce_order_partially_refunded_notification', array($this, 'refresh_email_lang'), 9); 
  43.  
  44. //new order admins email 
  45. add_action( 'woocommerce_order_status_pending_to_processing_notification', array( $this, 'new_order_admin_email' ), 9 ); 
  46. add_action( 'woocommerce_order_status_pending_to_completed_notification', array( $this, 'new_order_admin_email' ), 9 ); 
  47. add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $this, 'new_order_admin_email' ), 9 ); 
  48. add_action( 'woocommerce_order_status_failed_to_processing_notification', array( $this, 'new_order_admin_email' ), 9 ); 
  49. add_action( 'woocommerce_order_status_failed_to_completed_notification', array( $this, 'new_order_admin_email' ), 9 ); 
  50. add_action( 'woocommerce_order_status_failed_to_on-hold_notification', array( $this, 'new_order_admin_email' ), 9 ); 
  51. add_action( 'woocommerce_before_resend_order_emails', array( $this, 'backend_new_order_admin_email' ), 9 ); 
  52.  
  53. add_filter( 'icl_st_admin_string_return_cached', array( $this, 'admin_string_return_cached' ), 10, 2 ); 
  54.  
  55. add_filter( 'plugin_locale', array( $this, 'set_locale_for_emails' ), 10, 2 ); 
  56. add_filter( 'woocommerce_countries', array( $this, 'translate_woocommerce_countries' ) ); 
  57.  
  58. if( is_admin() && $pagenow == 'admin.php' && isset($_GET['page']) && $_GET['page'] == 'wc-settings' && isset($_GET['tab']) && $_GET['tab'] == 'email' ) { 
  59. add_action('admin_footer', array($this, 'show_language_links_for_wc_emails')); 
  60. $this->set_emails_string_language(); 
  61.  
  62. add_filter( 'get_post_metadata', array( $this, 'filter_payment_method_string' ), 10, 4 ); 
  63.  
  64. if( 
  65. !isset( $_GET['post_type'] ) || 
  66. $_GET['post_type'] != 'shop_order' 
  67. ) && 
  68. !isset( $_GET[ 'action' ] ) || 
  69. !in_array( $_GET['action'] , array( 'woocommerce_mark_order_complete', 'woocommerce_mark_order_status', 'mark_processing' ) ) 
  70. ) { 
  71. add_filter( 'woocommerce_order_items_meta_get_formatted', array( $this, 'filter_formatted_items' ), 10, 2 ); 
  72.  
  73. function email_refresh_in_ajax() { 
  74. if( isset( $_GET[ 'order_id' ] ) ) { 
  75. $this->refresh_email_lang( $_GET[ 'order_id' ] ); 
  76. $this->email_heading_completed( $_GET[ 'order_id' ], true ); 
  77.  
  78. function refresh_email_lang_complete( $order_id ) { 
  79.  
  80. $this->order_id = $order_id; 
  81. $this->refresh_email_lang( $order_id ); 
  82. $this->email_heading_completed( $order_id, true ); 
  83.  
  84. /** 
  85. * Translate WooCommerce emails. 
  86. * 
  87. * @global type $sitepress 
  88. * @global type $order_id 
  89. * @return type 
  90. */ 
  91. function email_header( $order ) { 
  92.  
  93. if( is_array( $order ) ) { 
  94. $order = $order[ 'order_id' ]; 
  95. } elseif( is_object( $order ) ) { 
  96. $order = method_exists( 'WC_Order', 'get_id' ) ? $order->get_id() : $order->id; 
  97.  
  98. $this->refresh_email_lang( $order ); 
  99.  
  100.  
  101. function refresh_email_lang( $order_id ) { 
  102.  
  103. if ( is_array( $order_id ) ) { 
  104. if ( isset( $order_id[ 'order_id' ] ) ) { 
  105. $order_id = $order_id[ 'order_id' ]; 
  106. } else { 
  107. return; 
  108.  
  109. $lang = get_post_meta( $order_id, 'wpml_language', true ); 
  110. if( !empty( $lang ) ) { 
  111. $this->change_email_language( $lang ); 
  112.  
  113. /** 
  114. * After email translation switch language to default. 
  115. */ 
  116. function email_footer() { 
  117. $this->sitepress->switch_lang( $this->sitepress->get_default_language() ); 
  118.  
  119. function comments_language() { 
  120. $this->change_email_language( $this->woocommerce_wpml->strings->get_domain_language( 'woocommerce' ) ); 
  121.  
  122.  
  123. function email_heading_completed( $order_id, $no_checking = false ) { 
  124. global $woocommerce; 
  125. if( ( class_exists( 'WC_Email_Customer_Completed_Order' ) || $no_checking ) && isset( $woocommerce->mailer()->emails[ 'WC_Email_Customer_Completed_Order' ] ) ) { 
  126.  
  127. $woocommerce->mailer()->emails['WC_Email_Customer_Completed_Order']->heading = $this->wcml_get_translated_email_string( 'admin_texts_woocommerce_customer_completed_order_settings', '[woocommerce_customer_completed_order_settings]heading' ); 
  128.  
  129. $woocommerce->mailer()->emails['WC_Email_Customer_Completed_Order']->subject = $this->wcml_get_translated_email_string( 'admin_texts_woocommerce_customer_completed_order_settings', '[woocommerce_customer_completed_order_settings]subject' ); 
  130.  
  131. $woocommerce->mailer()->emails['WC_Email_Customer_Completed_Order']->heading_downloadable = $this->wcml_get_translated_email_string( 'admin_texts_woocommerce_customer_completed_order_settings', '[woocommerce_customer_completed_order_settings]heading_downloadable' ); 
  132.  
  133. $woocommerce->mailer()->emails['WC_Email_Customer_Completed_Order']->subject_downloadable = $this->wcml_get_translated_email_string( 'admin_texts_woocommerce_customer_completed_order_settings', '[woocommerce_customer_completed_order_settings]subject_downloadable' ); 
  134.  
  135. $enabled = $woocommerce->mailer()->emails['WC_Email_Customer_Completed_Order']->enabled; 
  136. $woocommerce->mailer()->emails['WC_Email_Customer_Completed_Order']->enabled = false; 
  137. $woocommerce->mailer()->emails['WC_Email_Customer_Completed_Order']->trigger($order_id); 
  138. $woocommerce->mailer()->emails['WC_Email_Customer_Completed_Order']->enabled = $enabled; 
  139.  
  140. function email_heading_processing($order_id) { 
  141. global $woocommerce; 
  142. if( class_exists( 'WC_Email_Customer_Processing_Order' ) && isset( $woocommerce->mailer()->emails[ 'WC_Email_Customer_Processing_Order' ] ) ) { 
  143.  
  144. $woocommerce->mailer()->emails['WC_Email_Customer_Processing_Order']->heading = $this->wcml_get_translated_email_string( 'admin_texts_woocommerce_customer_processing_order_settings', '[woocommerce_customer_processing_order_settings]heading' ); 
  145.  
  146. $woocommerce->mailer()->emails['WC_Email_Customer_Processing_Order']->subject = $this->wcml_get_translated_email_string( 'admin_texts_woocommerce_customer_processing_order_settings', '[woocommerce_customer_processing_order_settings]subject' ); 
  147.  
  148. $enabled = $woocommerce->mailer()->emails['WC_Email_Customer_Processing_Order']->enabled; 
  149. $woocommerce->mailer()->emails['WC_Email_Customer_Processing_Order']->enabled = false; 
  150. $woocommerce->mailer()->emails['WC_Email_Customer_Processing_Order']->trigger($order_id); 
  151. $woocommerce->mailer()->emails['WC_Email_Customer_Processing_Order']->enabled = $enabled; 
  152.  
  153. function email_heading_note($args) { 
  154. global $woocommerce; 
  155.  
  156. if( class_exists( 'WC_Email_Customer_Note' ) && isset( $woocommerce->mailer()->emails[ 'WC_Email_Customer_Note' ] ) ) { 
  157.  
  158. $woocommerce->mailer()->emails['WC_Email_Customer_Note']->heading = $this->wcml_get_translated_email_string( 'admin_texts_woocommerce_customer_note_settings', '[woocommerce_customer_note_settings]heading' ); 
  159.  
  160. $woocommerce->mailer()->emails['WC_Email_Customer_Note']->subject = $this->wcml_get_translated_email_string( 'admin_texts_woocommerce_customer_note_settings', '[woocommerce_customer_note_settings]subject' ); 
  161.  
  162. $enabled = $woocommerce->mailer()->emails['WC_Email_Customer_Note']->enabled; 
  163. $woocommerce->mailer()->emails['WC_Email_Customer_Note']->enabled = false; 
  164. $woocommerce->mailer()->emails['WC_Email_Customer_Note']->trigger($args); 
  165. $woocommerce->mailer()->emails['WC_Email_Customer_Note']->enabled = $enabled; 
  166.  
  167. function email_heading_refund( $order_id, $refund_id = null ) { 
  168. global $woocommerce; 
  169. if( class_exists( 'WC_Email_Customer_Refunded_Order' ) && isset( $woocommerce->mailer()->emails[ 'WC_Email_Customer_Refunded_Order' ] ) ) { 
  170.  
  171. $woocommerce->mailer()->emails['WC_Email_Customer_Refunded_Order']->heading = 
  172. $this->wcml_get_translated_email_string( 'admin_texts_woocommerce_customer_refunded_order_settings',  
  173. '[woocommerce_customer_refunded_order_settings]heading_partial' ); 
  174. $woocommerce->mailer()->emails['WC_Email_Customer_Refunded_Order']->subject = 
  175. $this->wcml_get_translated_email_string( 'admin_texts_woocommerce_customer_refunded_order_settings',  
  176. '[woocommerce_customer_refunded_order_settings]subject_partial' ); 
  177.  
  178. $enabled = $woocommerce->mailer()->emails['WC_Email_Customer_Refunded_Order']->enabled; 
  179. $woocommerce->mailer()->emails['WC_Email_Customer_Refunded_Order']->enabled = false; 
  180. $woocommerce->mailer()->emails['WC_Email_Customer_Refunded_Order']->trigger($order_id, true, $refund_id); 
  181. $woocommerce->mailer()->emails['WC_Email_Customer_Refunded_Order']->enabled = $enabled; 
  182.  
  183.  
  184.  
  185. function new_order_admin_email($order_id) { 
  186. global $woocommerce; 
  187. if( isset( $woocommerce->mailer()->emails[ 'WC_Email_New_Order' ] ) ) { 
  188. $recipients = explode(', ', $woocommerce->mailer()->emails['WC_Email_New_Order']->get_recipient()); 
  189. foreach($recipients as $recipient) { 
  190. $user = get_user_by('email', $recipient); 
  191. if($user) { 
  192. $user_lang = $this->sitepress->get_user_admin_language($user->ID, true ); 
  193. }else{ 
  194. $user_lang = get_post_meta($order_id, 'wpml_language', true ); 
  195.  
  196. $this->change_email_language( $user_lang ); 
  197.  
  198. $woocommerce->mailer()->emails['WC_Email_New_Order']->heading = $this->wcml_get_translated_email_string( 'admin_texts_woocommerce_new_order_settings', '[woocommerce_new_order_settings]heading' ); 
  199.  
  200. $woocommerce->mailer()->emails['WC_Email_New_Order']->subject = $this->wcml_get_translated_email_string( 'admin_texts_woocommerce_new_order_settings', '[woocommerce_new_order_settings]subject' ); 
  201.  
  202. $woocommerce->mailer()->emails['WC_Email_New_Order']->recipient = $recipient; 
  203.  
  204. $woocommerce->mailer()->emails['WC_Email_New_Order']->trigger($order_id); 
  205. $woocommerce->mailer()->emails['WC_Email_New_Order']->enabled = false; 
  206. $this->refresh_email_lang($order_id); 
  207.  
  208. public function backend_new_order_admin_email( $order_id ) { 
  209. if( isset( $_POST[ 'wc_order_action' ] ) && $_POST[ 'wc_order_action' ] == 'send_email_new_order' ) { 
  210. $this->new_order_admin_email( $order_id ); 
  211.  
  212. function filter_payment_method_string( $check, $object_id, $meta_key, $single ) { 
  213. if( $meta_key == '_payment_method_title' ) { 
  214.  
  215. $payment_method = get_post_meta( $object_id, '_payment_method', true ); 
  216.  
  217. if( $payment_method ) { 
  218.  
  219. $payment_gateways = WC()->payment_gateways->payment_gateways(); 
  220. if( isset( $payment_gateways[ $payment_method ] ) ) { 
  221. $title = $this->woocommerce_wpml->gateways->translate_gateway_title( $payment_gateways[ $payment_method ]->title, $payment_method, $this->sitepress->get_current_language() ); 
  222.  
  223. return $title; 
  224.  
  225.  
  226. return $check; 
  227.  
  228. function filter_formatted_items( $formatted_meta, $object ) { 
  229.  
  230. if( isset( $object->product->variation_id ) ) { 
  231.  
  232. $current_prod_variation_id = apply_filters( 'translate_object_id', $object->product->variation_id, 'product_variation', false ); 
  233.  
  234. if( !is_null( $current_prod_variation_id ) ) { 
  235.  
  236. foreach( $formatted_meta as $key => $formatted_var ) { 
  237.  
  238. if( substr( $formatted_var[ 'key' ], 0, 3 ) ) { 
  239.  
  240. $attribute = wc_sanitize_taxonomy_name( $formatted_var[ 'key' ] ); 
  241.  
  242. if( taxonomy_exists( $attribute ) ) { 
  243. $attr_term = get_term_by( 'name', $formatted_meta[ $key ][ 'value' ], $attribute ); 
  244. $tr_id = apply_filters( 'translate_object_id', $attr_term->term_id, $attribute, false, $this->sitepress->get_current_language() ); 
  245.  
  246. if( $tr_id ) { 
  247. $translated_term = $this->woocommerce_wpml->terms->wcml_get_term_by_id( $tr_id, $attribute ); 
  248. $formatted_meta[ $key ][ 'value' ] = $translated_term->name; 
  249.  
  250. }else{ 
  251.  
  252. $custom_attr_trnsl = $this->woocommerce_wpml->attributes->get_custom_attribute_translation( $object->product->id, $formatted_var[ 'key' ], array('is_taxonomy' => false), $this->sitepress->get_current_language() ); 
  253.  
  254. if ( false !== $custom_attr_trnsl ) { 
  255. $formatted_meta[ $key ][ 'label' ] = $custom_attr_trnsl['name']; 
  256.  
  257. return $formatted_meta; 
  258.  
  259.  
  260. function change_email_language($lang) { 
  261. global $woocommerce; 
  262. $this->sitepress->switch_lang($lang, true); 
  263. $this->locale = $this->sitepress->get_locale( $lang ); 
  264. unload_textdomain('woocommerce'); 
  265. unload_textdomain( 'default' ); 
  266. global $wp_locale; 
  267. $wp_locale = new WP_Locale(); 
  268.  
  269. $woocommerce->load_plugin_textdomain(); 
  270. load_default_textdomain( $this->locale ); 
  271.  
  272. function admin_string_return_cached( $value, $option ) { 
  273. if( in_array( $option, array ( 'woocommerce_email_from_address', 'woocommerce_email_from_name' ) ) ) 
  274. return false; 
  275.  
  276. return $value; 
  277.  
  278. function wcml_get_translated_email_string( $context, $name ) { 
  279.  
  280. if( version_compare(WPML_ST_VERSION, '2.2.6', '<=' ) ) { 
  281. global $wpdb; 
  282.  
  283. $result = $wpdb->get_var( $wpdb->prepare( "SELECT value FROM {$wpdb->prefix}icl_strings WHERE context = %s AND name = %s ", $context, $name ) ); 
  284.  
  285. return apply_filters( 'wpml_translate_single_string', $result, $context, $name ); 
  286. }else{ 
  287.  
  288. return apply_filters( 'wpml_translate_single_string', false, $context, $name ); 
  289.  
  290.  
  291.  
  292. function icl_current_string_language( $current_language, $name ) { 
  293. $order_id = false; 
  294.  
  295. if( isset($_POST['action']) && $_POST['action'] == 'editpost' && isset($_POST['post_type']) && $_POST['post_type'] == 'shop_order' && isset( $_POST[ 'wc_order_action' ] ) && $_POST[ 'wc_order_action' ] != 'send_email_new_order' ) { 
  296. $order_id = filter_input( INPUT_POST, 'post_ID', FILTER_SANITIZE_NUMBER_INT ); 
  297. }elseif( isset($_POST['action']) && $_POST['action'] == 'woocommerce_add_order_note' && isset($_POST['note_type']) && $_POST['note_type'] == 'customer' ) { 
  298. $order_id = filter_input( INPUT_POST, 'post_id', FILTER_SANITIZE_NUMBER_INT ); 
  299. }elseif( isset($_GET['action']) && isset($_GET['order_id']) && ( $_GET['action'] == 'woocommerce_mark_order_complete' || $_GET['action'] == 'woocommerce_mark_order_status') ) { 
  300. $order_id = filter_input( INPUT_GET, 'order_id', FILTER_SANITIZE_NUMBER_INT ); 
  301. }elseif(isset($_GET['action']) && $_GET['action'] == 'mark_completed' && $this->order_id) { 
  302. $order_id = $this->order_id; 
  303. }elseif(isset($_POST['action']) && $_POST['action'] == 'woocommerce_refund_line_items') { 
  304. $order_id = filter_input( INPUT_POST, 'order_id', FILTER_SANITIZE_NUMBER_INT ); 
  305. }elseif( empty( $_POST ) && isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == 'wc-settings' && isset( $_GET[ 'tab' ] ) && $_GET[ 'tab' ] == 'email' && substr( $name, 0, 12 ) == '[woocommerce' ) { 
  306. $email_string = explode( ']', str_replace( '[', '', $name ) ); 
  307. $email_option = get_option( $email_string[ 0 ], true ); 
  308. $context = 'admin_texts_'.$email_string[ 0 ]; 
  309.  
  310. $current_language = $this->woocommerce_wpml->strings->get_string_language( $email_option[ $email_string[ 1 ] ], $context, $name ); 
  311.  
  312. $order_id = apply_filters( 'wcml_send_email_order_id', $order_id ); 
  313.  
  314. if( $order_id ) { 
  315. $order_language = get_post_meta( $order_id, 'wpml_language', true ); 
  316. if( $order_language ) { 
  317. $current_language = $order_language; 
  318. }else{ 
  319. $current_language = $this->sitepress->get_current_language(); 
  320.  
  321. return apply_filters( 'wcml_email_language', $current_language, $order_id ); 
  322.  
  323. // set correct locale code for emails 
  324. function set_locale_for_emails( $locale, $domain ) { 
  325.  
  326. if( $domain == 'woocommerce' && $this->locale ) { 
  327. $locale = $this->locale; 
  328.  
  329. return $locale; 
  330.  
  331. function show_language_links_for_wc_emails() { 
  332.  
  333. $emails_options = array( 
  334. 'woocommerce_new_order_settings',  
  335. 'woocommerce_cancelled_order_settings',  
  336. 'woocommerce_failed_order_settings',  
  337. 'woocommerce_customer_on_hold_order_settings',  
  338. 'woocommerce_customer_processing_order_settings',  
  339. 'woocommerce_customer_completed_order_settings',  
  340. 'woocommerce_customer_refunded_order_settings',  
  341. 'woocommerce_customer_invoice_settings',  
  342. 'woocommerce_customer_note_settings',  
  343. 'woocommerce_customer_reset_password_settings',  
  344. 'woocommerce_customer_new_account_settings' 
  345. ); 
  346.  
  347. $text_keys = array( 
  348. 'subject',  
  349. 'heading',  
  350. 'subject_downloadable',  
  351. 'heading_downloadable',  
  352. 'subject_full',  
  353. 'subject_partial',  
  354. 'heading_full',  
  355. 'heading_partial',  
  356. 'subject_paid',  
  357. 'heading_paid' 
  358. ); 
  359.  
  360.  
  361. foreach( $emails_options as $emails_option ) { 
  362.  
  363. $section_name = str_replace( 'woocommerce_', 'wc_email_', $emails_option ); 
  364. $section_name = str_replace( '_settings', '', $section_name ); 
  365. if( isset( $_GET['section'] ) && $_GET['section'] == $section_name ) { 
  366.  
  367. $option_settings = get_option( $emails_option ); 
  368. foreach ($option_settings as $setting_key => $setting_value) { 
  369. if ( in_array( $setting_key, $text_keys ) ) { 
  370. $input_name = str_replace( '_settings', '', $emails_option ).'_'.$setting_key; 
  371.  
  372. $lang_selector = new WPML_Simple_Language_Selector($this->sitepress); 
  373. $language = $this->woocommerce_wpml->strings->get_string_language( $setting_value, 'admin_texts_'.$emails_option, '['.$emails_option.']'.$setting_key ); 
  374. if( is_null( $language ) ) { 
  375. $language = $this->sitepress->get_default_language(); 
  376.  
  377. $lang_selector->render( array( 
  378. 'id' => $emails_option.'_'.$setting_key.'_language_selector',  
  379. 'name' => 'wcml_lang-'.$emails_option.'-'.$setting_key,  
  380. 'selected' => $language,  
  381. 'show_please_select' => false,  
  382. 'echo' => true,  
  383. 'style' => 'width: 18%;float: left' 
  384. ); 
  385.  
  386. $st_page = admin_url( 'admin.php?page=' . WPML_ST_FOLDER . '/menu/string-translation.php&context=admin_texts_'.$emails_option.'&search='.$setting_value ); 
  387. ?> 
  388. <script> 
  389. var input = jQuery('input[name="<?php echo $input_name ?>"]'); 
  390. if (input.length) { 
  391. input.parent().append('<div class="translation_controls"></div>'); 
  392. input.parent().find('.translation_controls').append('<a href="<?php echo $st_page ?>" style="margin-left: 10px"><?php _e('translations', 'woocommerce-multilingual') ?></a>'); 
  393. jQuery('#<?php echo $emails_option.'_'.$setting_key.'_language_selector' ?>').prependTo(input.parent().find('.translation_controls')); 
  394. </script> 
  395. <?php } 
  396.  
  397. function set_emails_string_language() { 
  398.  
  399. foreach( $_POST as $key => $language ) { 
  400.  
  401. if( substr( $key, 0, 9 ) == 'wcml_lang' ) { 
  402.  
  403. $email_string = explode( '-', $key ); 
  404.  
  405. if( isset( $email_string[2] ) ) { 
  406.  
  407. $email_key = str_replace( '_settings', '', $email_string[1] ); 
  408. $email_key .= '_'.$email_string[2]; 
  409.  
  410. $email_settings = get_option( $email_string[1], true ); 
  411. $opt_string_value = $email_settings[ $email_string[2] ]; 
  412.  
  413. $string_value = isset( $_POST[ $email_key ] ) ? $_POST[ $email_key ] : $opt_string_value; 
  414.  
  415. $context = 'admin_texts_'.$email_string[1]; 
  416. $name = '['.$email_string[1].']'.$email_string[2]; 
  417.  
  418. do_action('wpml_register_single_string', $context, $name, $string_value, false, $this->woocommerce_wpml->strings->get_string_language( $opt_string_value, $context ) ); 
  419.  
  420. $this->woocommerce_wpml->strings->set_string_language( $string_value, $context, $name, $language ); 
  421.  
  422. function translate_woocommerce_countries( $countries ) { 
  423.  
  424. if( isset( $_POST[ 'wc_order_action' ] ) && $_POST[ 'wc_order_action' ] !== 'send_email_new_order' && isset( $_POST[ 'post_ID' ] ) ) { 
  425. $this->refresh_email_lang( $_POST[ 'post_ID' ] ); 
  426. $countries = include( WC()->plugin_path() . '/i18n/countries.php' ); 
  427.  
  428. return $countries; 
  429.  
.