woocommerce_wpml

The WooCommerce Multilingual woocommerce wpml class.

Defined (1)

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

/inc/class-woocommerce-wpml.php  
  1. class woocommerce_wpml { 
  2.  
  3. /** @var woocommerce_wpml */ 
  4. protected static $_instance = null; 
  5.  
  6. public $settings; 
  7. /** @var WCML_Troubleshooting */ 
  8. public $troubleshooting; 
  9. /** @var WCML_Endpoints */ 
  10. public $endpoints; 
  11. /** @var WCML_Products */ 
  12. public $products; 
  13. /** @var WCML_Synchronize_Product_Data */ 
  14. public $sync_product_data; 
  15. /** @var WCML_Synchronize_Variations_Data */ 
  16. public $sync_variations_data; 
  17. /** @var WCML_Store_Pages */ 
  18. public $store; 
  19. /** @var WCML_Emails */ 
  20. public $emails; 
  21. /** @var WCML_Terms */ 
  22. public $terms; 
  23. /** @var WCML_Attributes */ 
  24. public $attributes; 
  25. /** @var WCML_Orders */ 
  26. public $orders; 
  27. /** @var WCML_Currencies */ 
  28. public $currencies; 
  29. /** @var WCML_Multi_Currency */ 
  30. public $multi_currency; 
  31. /** @var WCML_Languages_Upgrader */ 
  32. public $languages_upgrader; 
  33. /** @var WCML_Url_Translation */ 
  34. public $url_translation; 
  35. /** @var WCML_Coupons */ 
  36. public $coupons; 
  37. /** @var WCML_Locale */ 
  38. public $locale; 
  39. /** @var WCML_Media */ 
  40. public $media; 
  41. /** @var WCML_Downloadable_Products */ 
  42. public $downloadable; 
  43. /** @var WCML_WC_Strings */ 
  44. public $strings; 
  45. /** @var WCML_WC_Shipping */ 
  46. public $shipping; 
  47. /** @var WCML_WC_Gateways */ 
  48. public $gateways; 
  49. /** @var WCML_CS_Templates */ 
  50. public $cs_templates; 
  51.  
  52. /** @var WCML_Reports */ 
  53. private $reports; 
  54. /** @var WCML_Requests */ 
  55. public $requests; 
  56. /** @var WCML_Compatibility */ 
  57. // NOTE: revert back to private after wcml-1218 
  58. public $compatibility; 
  59. /** @var WCML_xDomain_Data */ 
  60. private $xdomain_data; 
  61.  
  62. /** 
  63. * @var WCML_Screen_Options 
  64. */ 
  65. private $wcml_products_screen; 
  66.  
  67.  
  68. public function __construct() { 
  69. global $sitepress; 
  70.  
  71. $this->settings = $this->get_settings(); 
  72. $this->currencies = new WCML_Currencies( $this ); 
  73. $this->xdomain_data = new WCML_xDomain_Data; 
  74.  
  75. new WCML_Widgets( $this ); 
  76.  
  77. if ( class_exists( 'WooCommerce' ) && defined( 'WC_VERSION' ) && 'yes' == get_option( 'woocommerce_api_enabled' ) && ! is_null( $sitepress ) ) { 
  78. if ( version_compare( WC_VERSION, '2.6', '>=' ) && WCML_REST_API_Support::is_rest_api_request() ) { 
  79. if( WCML_REST_API_Support::get_api_request_version() === 1 ) { 
  80. $wcml_rest_api_support = new WCML_REST_API_Support_V1( $this, $sitepress ); 
  81. }else{ 
  82. $wcml_rest_api_support = new WCML_REST_API_Support( $this, $sitepress ); 
  83. $wcml_rest_api_support->initialize(); 
  84. } else { 
  85. new WCML_WooCommerce_Rest_API_Support( $this, $sitepress ); 
  86.  
  87. add_action('init', array($this, 'init'), 2); 
  88.  
  89. if( defined( 'ICL_SITEPRESS_VERSION' ) && !ICL_PLUGIN_INACTIVE && class_exists( 'SitePress' ) ) { 
  90. $this->cs_templates = new WCML_Currency_Switcher_Templates( $this ); 
  91. $this->cs_templates->init_hooks(); 
  92.  
  93.  
  94.  
  95. /** 
  96. * Main instance. 
  97. * @since 3.8 
  98. * @static 
  99. * @return woocommerce_wpml 
  100. */ 
  101. public static function instance() { 
  102. global $woocommerce_wpml; 
  103.  
  104. if ( is_null( self::$_instance ) ) { 
  105. self::$_instance = new self(); 
  106. $woocommerce_wpml = self::$_instance; 
  107.  
  108. return self::$_instance; 
  109. public function init() { 
  110. global $sitepress, $wpdb, $woocommerce; 
  111.  
  112. new WCML_Upgrade; 
  113.  
  114. $this->dependencies = new WCML_Dependencies; 
  115. $this->check_dependencies = $this->dependencies->check(); 
  116.  
  117. WCML_Admin_Menus::set_up_menus( $this, $sitepress, $wpdb, $this->check_dependencies ); 
  118.  
  119. if( !$this->check_dependencies ) { 
  120. WCML_Capabilities::set_up_capabilities(); 
  121.  
  122. wp_register_style( 'otgs-ico', WCML_PLUGIN_URL . '/res/css/otgs-ico.css', null, WCML_VERSION ); 
  123. wp_enqueue_style( 'otgs-ico'); 
  124.  
  125. WCML_Resources::load_management_css(); 
  126. WCML_Resources::load_tooltip_resources(); 
  127. return false; 
  128.  
  129. $this->compatibility = new WCML_Compatibility( $sitepress, $this, $wpdb ); 
  130.  
  131. $actions_that_need_mc = array( 
  132. 'save-mc-options',  
  133. 'wcml_new_currency',  
  134. 'wcml_save_currency',  
  135. 'wcml_delete_currency',  
  136. 'wcml_update_currency_lang',  
  137. 'wcml_update_default_currency',  
  138. 'wcml_price_preview',  
  139. 'wcml_currencies_switcher_preview',  
  140. 'wcml_currencies_switcher_save_settings',  
  141. 'wcml_delete_currency_switcher',  
  142. 'wcml_currencies_order' 
  143. ); 
  144. if($this->settings['enable_multi_currency'] == WCML_MULTI_CURRENCIES_INDEPENDENT 
  145. || ( isset($_GET['page']) && $_GET['page'] == 'wpml-wcml' && isset($_GET['tab']) && $_GET['tab'] == 'multi-currency' ) 
  146. || ( isset( $_POST[ 'action' ] ) && in_array( $_POST[ 'action' ], $actions_that_need_mc ) ) 
  147. ) { 
  148. $this->multi_currency = new WCML_Multi_Currency; 
  149. }else{ 
  150. add_shortcode('currency_switcher', '__return_empty_string'); 
  151.  
  152. if( is_admin() ) { 
  153. $this->troubleshooting = new WCML_Troubleshooting( $this, $sitepress, $wpdb ); 
  154. $this->links = new WCML_Links($this, $sitepress); 
  155. $this->translation_editor = new WCML_Translation_Editor($this, $sitepress, $wpdb); 
  156. $this->languages_upgrader = new WCML_Languages_Upgrader; 
  157. $this->sync_variations_data = new WCML_Synchronize_Variations_Data($this, $sitepress, $wpdb); 
  158. $this->wcml_products_screen = new WCML_Products_Screen_Options($sitepress); 
  159. $this->wcml_products_screen->init(); 
  160. new WCML_Pointers(); 
  161.  
  162. $this->sync_product_data = new WCML_Synchronize_Product_Data( $this, $sitepress, $wpdb ); 
  163. $this->duplicate_product = new WCML_WC_Admin_Duplicate_Product( $this, $sitepress, $wpdb ); 
  164. $this->products = new WCML_Products( $this, $sitepress, $wpdb ); 
  165. $this->products->add_hooks(); 
  166. $this->store = new WCML_Store_Pages ($this, $sitepress ) ; 
  167. $this->emails = new WCML_Emails( $this, $sitepress ); 
  168. $this->terms = new WCML_Terms( $this, $sitepress, $wpdb ); 
  169. $this->attributes = new WCML_Attributes( $this, $sitepress, $wpdb ); 
  170. $this->orders = new WCML_Orders( $this, $sitepress ); 
  171. $this->strings = new WCML_WC_Strings; 
  172. $this->shipping = new WCML_WC_Shipping( $sitepress ); 
  173. $this->shipping->add_hooks(); 
  174. $this->gateways = new WCML_WC_Gateways( $this, $sitepress ); 
  175. $this->currencies = new WCML_Currencies( $this ); 
  176. $this->url_translation = new WCML_Url_Translation ( $this, $sitepress ); 
  177. $this->url_translation->set_up(); 
  178. $this->endpoints = new WCML_Endpoints( $this ); 
  179. $this->requests = new WCML_Requests; 
  180. $this->cart = new WCML_Cart( $this, $sitepress, $woocommerce ); 
  181. $this->coupons = new WCML_Coupons( $this, $sitepress ); 
  182. $this->locale = new WCML_Locale( $this, $sitepress ); 
  183. $this->media = new WCML_Media( $this, $sitepress, $wpdb ); 
  184. $this->downloadable = new WCML_Downloadable_Products( $this, $sitepress ); 
  185. $this->page_builders = new WCML_Page_Builders( $sitepress ); 
  186. $this->reports = new WCML_Reports; 
  187. $this->wcml_products_screen = new WCML_Products_Screen_Options(); 
  188. $this->wcml_products_screen->init(); 
  189.  
  190. new WCML_Ajax_Setup( $sitepress ); 
  191. new WCML_Fix_Copied_Custom_Fields_WPML353(); 
  192.  
  193. WCML_Install::initialize( $this, $sitepress ); 
  194.  
  195. WCML_Resources::set_up_resources( $this, $sitepress ); 
  196.  
  197. add_filter('woocommerce_get_checkout_payment_url', array('WCML_Links', 'filter_woocommerce_redirect_location')); 
  198. add_filter('woocommerce_get_cancel_order_url', array('WCML_Links', 'filter_woocommerce_redirect_location')); 
  199. add_filter('woocommerce_get_return_url', array('WCML_Links', 'filter_woocommerce_redirect_location')); 
  200.  
  201. add_action('wp_ajax_wcml_update_setting_ajx', array($this, 'update_setting_ajx')); 
  202.  
  203. if( is_admin() ) { 
  204. $taxonomy_translation_link_filters = new WCML_Taxonomy_Translation_Link_Filters( $this->attributes ); 
  205. $taxonomy_translation_link_filters->add_filters(); 
  206.  
  207. public function get_settings() { 
  208.  
  209. $defaults = array( 
  210. 'file_path_sync' => 1,  
  211. 'is_term_order_synced' => 0,  
  212. 'enable_multi_currency' => WCML_MULTI_CURRENCIES_DISABLED,  
  213. 'dismiss_doc_main' => 0,  
  214. 'trnsl_interface' => 1,  
  215. 'currency_options' => array(),  
  216. 'currency_switcher_product_visibility' => 1,  
  217. 'dismiss_tm_warning' => 0,  
  218. 'cart_sync' => array( 
  219. 'lang_switch' => WCML_CART_SYNC,  
  220. 'currency_switch' => WCML_CART_SYNC 
  221. ); 
  222.  
  223. if(empty($this->settings)) { 
  224. $this->settings = get_option('_wcml_settings'); 
  225.  
  226. foreach($defaults as $key => $value) { 
  227. if(!isset($this->settings[$key])) { 
  228. $this->settings[$key] = $value; 
  229.  
  230. return $this->settings; 
  231.  
  232. public function update_settings($settings = null) { 
  233. if(!is_null($settings)) { 
  234. $this->settings = $settings; 
  235. update_option('_wcml_settings', $this->settings); 
  236.  
  237. public function update_setting_ajx() { 
  238. $nonce = filter_input( INPUT_POST, 'nonce', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); 
  239. if(!$nonce || !wp_verify_nonce($nonce, 'wcml_settings')) { 
  240. die('Invalid nonce'); 
  241.  
  242. $data = $_POST; 
  243. $error = ''; 
  244. $html = ''; 
  245.  
  246. $this->settings[$data['setting']] = $data['value']; 
  247. $this->update_settings(); 
  248.  
  249. echo json_encode(array('html' => $html, 'error'=> $error)); 
  250. exit; 
  251.  
  252. //get latest stable version from WC readme.txt 
  253. public function get_stable_wc_version() { 
  254. global $woocommerce; 
  255.  
  256. $file = $woocommerce->plugin_path(). '/readme.txt'; 
  257. $values = file($file); 
  258. $wc_info = explode( ':', $values[5] ); 
  259. if( $wc_info[0] == 'Stable tag' ) { 
  260. $version = trim( $wc_info[1] ); 
  261. }else{ 
  262. foreach( $values as $value ) { 
  263. $wc_info = explode( ':', $value ); 
  264.  
  265. if( $wc_info[0] == 'Stable tag' ) { 
  266. $version = trim( $wc_info[1] ); 
  267.  
  268. return $version; 
  269.  
  270. public function get_supported_wp_version() { 
  271. $file = WCML_PLUGIN_PATH. '/readme.txt'; 
  272.  
  273. $values = file($file); 
  274.  
  275. $version = explode( ':', $values[6] ); 
  276.  
  277. if( $version[0] == 'Tested up to' ) { 
  278. return $version[1]; 
  279.  
  280. foreach( $values as $value ) { 
  281. $version = explode( ':', $value ); 
  282.  
  283. if( $version[0] == 'Tested up to' ) { 
  284. return $version[1]; 
  285.  
  286.