WCML_Emails

The WooCommerce Multilingual WCML Emails class.

Defined (1)

The class is defined in the following location(s).

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