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_Dependencies::instance()->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_germanized()->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. $this->filter_page_ids(); 
  26.  
  27. public function send_order_admin_confirmation( $order_id ) { 
  28. global $woocommerce_wpml; 
  29.  
  30. if ( isset( $woocommerce_wpml ) && isset( $woocommerce_wpml->emails ) && is_object( $woocommerce_wpml->emails ) ) { 
  31.  
  32. // Instantiate mailer to make sure that new order email is known 
  33. $mailer = WC()->mailer(); 
  34.  
  35. if ( method_exists( $woocommerce_wpml->emails, 'admin_email' ) ) 
  36. $woocommerce_wpml->emails->admin_email( $order_id ); 
  37. else if ( method_exists( $woocommerce_wpml->emails, 'new_order_admin_email' ) ) 
  38. $woocommerce_wpml->emails->new_order_admin_email( $order_id ); 
  39.  
  40. // Stop Germanized from sending the notification 
  41. add_filter( 'woocommerce_germanized_order_email_admin_confirmation_sent', array( $this, 'set_order_admin_confirmation' ) ); 
  42.  
  43. public function set_order_admin_confirmation( $is_sent ) { 
  44. return true; 
  45.  
  46. public function unregister_order_confirmation_hooks() { 
  47.  
  48. global $woocommerce_wpml; 
  49.  
  50. if ( isset( $woocommerce_wpml ) ) { 
  51. $statuses = array( 
  52. 'woocommerce_order_status_pending_to_processing_notification',  
  53. 'woocommerce_order_status_pending_to_completed_notification',  
  54. 'woocommerce_order_status_pending_to_on-hold_notification',  
  55. ); 
  56.  
  57. foreach ( $statuses as $status ) { 
  58. if ( method_exists( $woocommerce_wpml->emails, 'admin_email' ) ) 
  59. remove_action( $status, array( $woocommerce_wpml->emails, 'admin_email' ), 9 ); 
  60. else if ( method_exists( $woocommerce_wpml->emails, 'new_order_admin_email' ) ) 
  61. remove_action( $status, array( $woocommerce_wpml->emails, 'new_order_admin_email' ), 9 ); 
  62.  
  63. public function observe_order_update( $post_id, $post_after, $post_before ) { 
  64.  
  65. if ( 'shop_order' === $post_after->post_type ) { 
  66.  
  67. do_action( 'woocommerce_gzd_before_order_post_status', $post_id ); 
  68.  
  69. $order = wc_get_order( $post_id ); 
  70. $lang = null; 
  71.  
  72. // Reset GZD Locale 
  73. if ( $lang = get_post_meta( $post_id, 'wpml_language', true ) ) { 
  74. $this->set_language( $lang ); 
  75.  
  76.  
  77. public function set_language( $lang ) { 
  78.  
  79. global $sitepress, $woocommerce; 
  80.  
  81. $sitepress->switch_lang( $lang, true ); 
  82. $this->locale = $sitepress->get_locale( $lang ); 
  83.  
  84. add_filter( 'plugin_locale', array( $this, 'set_locale' ), 10, 2 ); 
  85.  
  86. unload_textdomain( 'woocommerce' ); 
  87. unload_textdomain( 'woocommerce-germanized' ); 
  88. unload_textdomain( 'woocommerce-germanized-pro' ); 
  89. unload_textdomain( 'default' ); 
  90.  
  91. $woocommerce->load_plugin_textdomain(); 
  92. WC_germanized()->load_plugin_textdomain(); 
  93.  
  94. do_action( 'woocommerce_gzd_wpml_lang_changed', $lang ); 
  95.  
  96. load_default_textdomain(); 
  97.  
  98. global $wp_locale; 
  99. $wp_locale = new WP_Locale(); 
  100.  
  101.  
  102. public function set_locale( $locale, $domain ) { 
  103.  
  104. if( in_array( $domain, array( 'woocommerce', 'woocommerce-germanized', 'woocommerce-germanized-pro' ) ) && $this->locale ) { 
  105. $locale = $this->locale; 
  106.  
  107. return $locale; 
  108.  
  109. public function filter_page_ids() { 
  110.  
  111. $woo_pages = array( 
  112. 'revocation_page_id',  
  113. 'data_security_page_id',  
  114. 'imprint_page_id',  
  115. 'payment_methods_page_id',  
  116. 'shipping_costs_page_id' 
  117. ); 
  118.  
  119. foreach ( $woo_pages as $page ) { 
  120. add_filter( 'woocommerce_get_' . $page, array( $this, 'translate_page' ) ); 
  121. add_filter( 'option_woocommerce_' . $page, array( $this, 'translate_page') ); 
  122.  
  123. public function translate_page( $id ) { 
  124.  
  125. global $pagenow; 
  126.  
  127. if( is_admin() && $pagenow == 'options-permalink.php' ) 
  128. return $id; 
  129.  
  130. return apply_filters( 'translate_object_id', $id, 'page', true ); 
  131.