WC_GZD_Compatibility_Wpml

WPML Helper.

Defined (1)

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

/includes/compatibility/class-wc-gzd-compatibility-wpml.php  
  1. class WC_GZD_Compatibility_Wpml extends WC_GZD_Compatibility { 
  2.  
  3. public function __construct() { 
  4. parent::__construct(  
  5. 'WPML',  
  6. 'sitepress-multilingual-cms/sitepress.php',  
  7. array(  
  8. 'version' => get_option( 'icl_sitepress_version', '1.0.0' ) 
  9. )  
  10. ); 
  11.  
  12. public function is_activated() { 
  13. return parent::is_activated() && wc_gzd_get_dependencies()->is_plugin_activated( 'woocommerce-multilingual/wpml-woocommerce.php' ); 
  14.  
  15. public function load() { 
  16.  
  17. // Observe order update and trigger hook 
  18. add_action( 'post_updated', array( $this, 'observe_order_update' ), 0, 3 ); 
  19.  
  20. // Prevent double sending order confirmation email to admin 
  21. if ( wc_gzd_send_instant_order_confirmation() ) { 
  22. add_action( 'wp_loaded', array( $this, 'unregister_order_confirmation_hooks' ) ); 
  23. add_action( 'woocommerce_germanized_before_order_confirmation', array( $this, 'send_order_admin_confirmation' ) ); 
  24.  
  25. add_action( 'woocommerce_gzd_get_term', array( $this, 'unhook_terms_clause' ), 10 ); 
  26. add_action( 'woocommerce_gzd_after_get_term', array( $this, 'rehook_terms_clause' ), 10 ); 
  27.  
  28. $this->filter_page_ids(); 
  29.  
  30. public function unhook_terms_clause() { 
  31. global $sitepress; 
  32.  
  33. remove_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ), 10, 4 ); 
  34.  
  35. public function rehook_terms_clause() { 
  36. global $sitepress; 
  37.  
  38. add_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ), 10, 4 ); 
  39.  
  40. public function send_order_admin_confirmation( $order_id ) { 
  41. global $woocommerce_wpml; 
  42.  
  43. if ( isset( $woocommerce_wpml ) && isset( $woocommerce_wpml->emails ) && is_object( $woocommerce_wpml->emails ) ) { 
  44.  
  45. // Instantiate mailer to make sure that new order email is known 
  46. $mailer = WC()->mailer(); 
  47.  
  48. if ( method_exists( $woocommerce_wpml->emails, 'admin_email' ) ) 
  49. $woocommerce_wpml->emails->admin_email( $order_id ); 
  50. elseif ( method_exists( $woocommerce_wpml->emails, 'new_order_admin_email' ) ) 
  51. $woocommerce_wpml->emails->new_order_admin_email( $order_id ); 
  52.  
  53. // Stop Germanized from sending the notification 
  54. add_filter( 'woocommerce_germanized_order_email_admin_confirmation_sent', array( $this, 'set_order_admin_confirmation' ) ); 
  55.  
  56. public function set_order_admin_confirmation( $is_sent ) { 
  57. return true; 
  58.  
  59. public function unregister_order_confirmation_hooks() { 
  60.  
  61. global $woocommerce_wpml; 
  62.  
  63. if ( isset( $woocommerce_wpml ) ) { 
  64. $statuses = array( 
  65. 'woocommerce_order_status_pending_to_processing_notification',  
  66. 'woocommerce_order_status_pending_to_completed_notification',  
  67. 'woocommerce_order_status_pending_to_on-hold_notification',  
  68. ); 
  69.  
  70. foreach ( $statuses as $status ) { 
  71. if ( method_exists( $woocommerce_wpml->emails, 'admin_email' ) ) 
  72. remove_action( $status, array( $woocommerce_wpml->emails, 'admin_email' ), 9 ); 
  73. elseif ( method_exists( $woocommerce_wpml->emails, 'new_order_admin_email' ) ) 
  74. remove_action( $status, array( $woocommerce_wpml->emails, 'new_order_admin_email' ), 9 ); 
  75.  
  76. public function observe_order_update( $post_id, $post_after, $post_before ) { 
  77.  
  78. if ( 'shop_order' === $post_after->post_type ) { 
  79.  
  80. do_action( 'woocommerce_gzd_before_order_post_status', $post_id ); 
  81.  
  82. $order = wc_get_order( $post_id ); 
  83. $lang = null; 
  84.  
  85. // Reset GZD Locale 
  86. if ( $lang = get_post_meta( $post_id, 'wpml_language', true ) ) { 
  87. $this->set_language( $lang ); 
  88.  
  89.  
  90. public function set_language( $lang ) { 
  91.  
  92. global $sitepress, $woocommerce; 
  93.  
  94. $sitepress->switch_lang( $lang, true ); 
  95. $this->locale = $sitepress->get_locale( $lang ); 
  96.  
  97. add_filter( 'plugin_locale', array( $this, 'set_locale' ), 10, 2 ); 
  98.  
  99. unload_textdomain( 'woocommerce' ); 
  100. unload_textdomain( 'woocommerce-germanized' ); 
  101. unload_textdomain( 'woocommerce-germanized-pro' ); 
  102. unload_textdomain( 'default' ); 
  103.  
  104. $woocommerce->load_plugin_textdomain(); 
  105. WC_germanized()->load_plugin_textdomain(); 
  106.  
  107. do_action( 'woocommerce_gzd_wpml_lang_changed', $lang ); 
  108.  
  109. load_default_textdomain(); 
  110.  
  111. global $wp_locale; 
  112. $wp_locale = new WP_Locale(); 
  113.  
  114.  
  115. public function set_locale( $locale, $domain ) { 
  116.  
  117. if( in_array( $domain, array( 'woocommerce', 'woocommerce-germanized', 'woocommerce-germanized-pro' ) ) && $this->locale ) { 
  118. $locale = $this->locale; 
  119.  
  120. return $locale; 
  121.  
  122. public function filter_page_ids() { 
  123.  
  124. $woo_pages = array( 
  125. 'revocation_page_id',  
  126. 'data_security_page_id',  
  127. 'imprint_page_id',  
  128. 'payment_methods_page_id',  
  129. 'shipping_costs_page_id' 
  130. ); 
  131.  
  132. foreach ( $woo_pages as $page ) { 
  133. add_filter( 'woocommerce_get_' . $page, array( $this, 'translate_page' ) ); 
  134. add_filter( 'option_woocommerce_' . $page, array( $this, 'translate_page') ); 
  135.  
  136. public function translate_page( $id ) { 
  137.  
  138. global $pagenow; 
  139.  
  140. if( is_admin() && $pagenow == 'options-permalink.php' ) 
  141. return $id; 
  142.  
  143. return apply_filters( 'translate_object_id', $id, 'page', true ); 
  144.