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 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.9.0 4.9.1 5.0.1 5.0.2 5.1.1 5.1.2 5.1.3 5.2.0 5.2.1 5.3.2 5.3.3.1 5.3.4 5.3.5 5.3.6 5.3.7
woocommerce-multilingual / classes / class-woocommerce-wpml.php
woocommerce-multilingual / classes Last commit date
API 1 week ago AdminDashboard 1 week ago AdminNotices 1 week ago AdminTexts 3 years ago Attributes 1 week ago Block 1 week ago CLI 5 years ago COT 1 week ago CacheInvalidate 1 week ago Container 1 week ago Coupons 1 week ago DisplayAsTranslated 1 week ago DownloadableFiles 1 week ago EditorScopedSync 1 week ago Email 1 week ago Endpoints 1 week ago Exporter 1 week ago HomeScreen 1 month ago Importer 1 week ago MO 1 week ago Multicurrency 1 week ago Options 1 week ago OrderItems 1 week ago Orders 1 week ago PaymentGateways 1 week ago Permalinks 1 week ago PointerUi 1 week ago PostHog 1 month ago Reports 1 week ago Rest 1 week ago Reviews 1 week ago RewriteRules 1 week ago StandAlone 1 week ago Synchronization 1 week ago TMDashboard 1 week ago Tax 1 week ago Terms 1 week ago TranslationControls 1 week ago TranslationJob 1 week ago User 1 week ago Utilities 1 week ago WcEmailSettings 1 week ago currencies 1 week ago media 1 week ago multi-currency 1 week ago order-property-filter 1 week ago pointers 1 week ago privacy 1 week ago product 1 week ago shortcodes 1 week ago taxonomy-translation 1 week ago templates 1 week ago url-filters 1 week ago urls 1 week ago wcml-setup 1 week ago class-wcml-admin-cookie.php 1 week ago class-wcml-tracking-link.php 1 week ago class-woocommerce-wpml.php 1 week ago
class-woocommerce-wpml.php
391 lines
1 <?php
2
3 use WCML\Utilities\AdminPages;
4 use function WCML\functions\getSitePress;
5 use function WCML\functions\isStandAlone;
6 use function WPML\Container\make;
7
8 class woocommerce_wpml {
9
10 public $settings;
11 public $troubleshooting;
12 public $endpoints;
13 public $products;
14 public $sync_product_data;
15 public $sync_variations_data;
16 public $store;
17 public $emails;
18 public $terms;
19 public $attributes;
20 public $orders;
21 public $currencies;
22 public ?WCML_Multi_Currency $multi_currency = null;
23 public $languages_upgrader;
24 public $url_translation;
25 public $coupons;
26 public $locale;
27 public $media;
28 public $downloadable;
29 public $strings;
30 public $shipping;
31 public ?WCML_WC_Gateways $gateways = null;
32 public $cs_templates;
33 public $comments;
34 public $translation_editor;
35
36 public $cart;
37 public $cart_sync_warnings;
38
39 public $requests;
40 public $compatibility;
41 public $cs_properties;
42 public $duplicate_product;
43 public $page_builders;
44
45 private $wcml_products_screen;
46
47 public function __construct() {
48 $sitepress = getSitePress();
49
50 $this->settings = $this->get_settings();
51 $this->currencies = new WCML_Currencies( $this );
52
53 new WCML_Widgets( $this );
54
55 add_action( 'init', [ $this, 'init' ], 2 );
56
57 $this->cs_properties = new WCML_Currency_Switcher_Properties();
58 $wpml_wp_api = $sitepress->get_wp_api();
59 $wpml_wp_api->get_wp_filesystem_direct();
60
61 $this->cs_templates = new WCML_Currency_Switcher_Templates( $this, $wpml_wp_api, make( WPML_File::class ) );
62 $this->cs_templates->init_hooks();
63
64 $wc_shortccode_product_category = new WCML_WC_Shortcode_Product_Category( $sitepress );
65 $wc_shortccode_product_category->add_hooks();
66 }
67
68 private function load_rest_api() {
69 $sitepress = getSitePress();
70
71 if ( class_exists( 'WooCommerce' ) && defined( 'WC_VERSION' ) && ( $sitepress instanceof \WPML\Core\ISitePress ) && WCML\Rest\Functions::isRestApiRequest() ) {
72 WCML\Rest\Hooks::addHooks();
73 }
74 }
75
76 public function add_hooks() {
77 add_action( 'wpml_loaded', [ $this, 'load' ] );
78 add_action( 'init', [ $this, 'init' ], 2 );
79 }
80
81 public function load() {
82 do_action( 'wcml_loaded' );
83 }
84
85 public function init(): void {
86 global $wpdb, $woocommerce, $wpml_url_converter, $wpml_post_translations, $wpml_term_translations;
87
88 $sitepress = getSitePress();
89
90 WCML_Admin_Menus::set_up_menus( $this, $sitepress, $wpdb );
91
92 if ( ! \WPML\Container\make( WCML_Dependencies::class )->check() ) {
93 if ( is_admin() && AdminPages::isWcmlSettings() ) {
94 WCML_Capabilities::set_up_capabilities();
95
96 wp_enqueue_style( 'otgs-icons' );
97
98 WCML_Resources::load_management_css();
99 WCML_Resources::load_tooltip_resources();
100 }
101
102 return;
103 }
104
105 new WCML_Upgrade();
106
107 $actions_that_need_mc = [
108 'save-mc-options',
109 'wcml_save_currency',
110 'wcml_delete_currency',
111 'wcml_update_currency_lang',
112 'wcml_update_default_currency',
113 'wcml_price_preview',
114 'wcml_currencies_switcher_preview',
115 'wcml_currencies_switcher_save_settings',
116 'wcml_delete_currency_switcher',
117 'wcml_currencies_order',
118 'wcml_set_currency_mode',
119 'wcml_set_max_mind_key',
120 ];
121
122 $this->cart = new WCML_Cart( $this, $sitepress, $woocommerce );
123
124 $this->compatibility = new WCML_Compatibility();
125 $this->compatibility->init_before_multicurrency();
126
127 $action = filter_input( INPUT_POST, 'action' );
128 if ( WCML_MULTI_CURRENCIES_INDEPENDENT === (int) $this->settings['enable_multi_currency']
129 || AdminPages::isMultiCurrency()
130 || ( in_array( $action, $actions_that_need_mc, true ) )
131 ) {
132 $this->get_multi_currency();
133 $wcml_price_filters = new WCML_Price_Filter( $this );
134 $wcml_price_filters->add_hooks();
135 } else {
136 add_shortcode( 'currency_switcher', '__return_empty_string' );
137 }
138
139 $this->compatibility->init();
140
141 if ( isStandAlone() ) {
142 $this->init_standalone( $sitepress, $wpdb );
143 return;
144 } else {
145 $this->init_full( $sitepress, $wpdb, $woocommerce, $wpml_url_converter, $wpml_post_translations, $wpml_term_translations );
146 return;
147 }
148 }
149
150 private function init_full( SitePress $sitepress, wpdb $wpdb, $woocommerce, $wpml_url_converter, $wpml_post_translations, $wpml_term_translations ): bool {
151 $this->currencies = new WCML_Currencies( $this );
152 $this->currencies->add_hooks();
153
154 $this->sync_variations_data = new WCML_Synchronize_Variations_Data( $this, $sitepress, $wpdb );
155
156 if ( is_admin() || wpml_is_rest_request() ) {
157 $this->translation_editor = new WCML_Translation_Editor( $this, $sitepress, $wpdb );
158 $this->translation_editor->add_hooks();
159 $tp_support = new WCML_TP_Support( $this, $wpdb, new WPML_Element_Translation_Package(), $sitepress->get_setting( 'translation-management', [] ) );
160 $tp_support->add_hooks();
161 $sync_downloadable_files_from_ATE = new \WCML\DownloadableFiles\SyncDownloadableFilesFromATE();
162 $sync_downloadable_files_from_ATE->add_hooks();
163 }
164
165 if ( is_admin() ) {
166 $this->sync_variations_data->add_hooks();
167 $this->troubleshooting = new WCML_Troubleshooting( $this, $sitepress, $wpdb );
168 $this->languages_upgrader = new WCML_Languages_Upgrader();
169 $this->wcml_products_screen = new WCML_Products_Screen_Options();
170 $this->wcml_products_screen->init();
171 $wcml_pointers = new WCML_Pointers();
172 $wcml_pointers->add_hooks();
173 }
174
175 $this->sync_product_data = new WCML_Synchronize_Product_Data( $this, $sitepress, $wpml_post_translations, $wpdb );
176 $this->sync_product_data->add_hooks();
177 $this->duplicate_product = new WCML_WC_Admin_Duplicate_Product( $this, $sitepress, $wpdb );
178 $this->products = new WCML_Products( $this, $sitepress, $wpml_post_translations, $wpdb );
179 $this->products->add_hooks();
180 $this->store = new WCML_Store_Pages( $this, $sitepress );
181 $this->store->add_hooks();
182 $this->strings = new WCML_WC_Strings( $this, $sitepress, $wpdb );
183 $this->strings->add_hooks();
184 $this->emails = new WCML_Emails( $this->strings, $sitepress, $woocommerce );
185 $this->emails->add_hooks();
186 $this->terms = new WCML_Terms( $this, $sitepress, $wpdb );
187 $this->terms->add_hooks();
188 $this->attributes = new WCML_Attributes( $this, $sitepress, $wpml_post_translations, $wpml_term_translations, $wpdb );
189 $this->attributes->add_hooks();
190 $this->orders = new WCML_Orders( $this, $sitepress );
191 $this->shipping = new WCML_WC_Shipping( $sitepress );
192 $this->shipping->add_hooks();
193 $this->gateways = new WCML_WC_Gateways( $this, $sitepress );
194 $this->gateways->add_hooks();
195 $this->url_translation = new WCML_Url_Translation( $this, $sitepress, $wpdb );
196 $this->url_translation->set_up();
197 $this->endpoints = new WCML_Endpoints( $this, $sitepress, $wpdb );
198 $this->endpoints->add_hooks();
199 $this->requests = new WCML_Requests();
200 $this->cart->add_hooks();
201 $this->coupons = new WCML_Coupons( $sitepress );
202 $this->coupons->add_hooks();
203 $this->locale = new WCML_Locale( $sitepress );
204 $this->media = WCML\Media\Wrapper\Factory::create();
205 $this->media->add_hooks();
206 $this->downloadable = new WCML_Downloadable_Products( $this, $sitepress, $wpdb );
207 $this->downloadable->add_hooks();
208 $this->page_builders = new WCML_Page_Builders( $sitepress );
209 $this->wcml_products_screen = new WCML_Products_Screen_Options();
210 $this->wcml_products_screen->init();
211 $this->cart_sync_warnings = new WCML_Cart_Sync_Warnings( $this, $sitepress );
212 $this->cart_sync_warnings->add_hooks();
213 $this->comments = new WCML_Comments( $this, $sitepress, $wpml_post_translations, $wpdb );
214 $this->comments->add_hooks();
215
216 if ( is_admin() ) {
217 $taxonomy_translation_link_filters = new WCML_Taxonomy_Translation_Link_Filters( $this->attributes );
218 $taxonomy_translation_link_filters->add_filters();
219 }
220
221 $payment_method_filter = new WCML_Payment_Method_Filter();
222 $payment_method_filter->add_hooks();
223
224 $wcml_ajax_setup = new WCML_Ajax_Setup( $sitepress );
225 $wcml_ajax_setup->add_hooks();
226 WCML_Install::initialize( $this, $sitepress );
227
228 WCML_Resources::set_up_resources( $this, $sitepress );
229 WCML_Resources::add_hooks();
230
231 $url_filters_redirect_location = new WCML_Url_Filters_Redirect_Location( $wpml_url_converter );
232 $url_filters_redirect_location->add_hooks();
233
234 $this->load_rest_api();
235
236 return true;
237 }
238
239 private function init_standalone( \WPML\Core\ISitePress $sitepress, wpdb $wpdb ): bool {
240 $this->currencies = new WCML_Currencies( $this );
241 $this->currencies->add_hooks();
242
243 if ( is_admin() ) {
244 ( new WCML_Pointers() )->add_hooks();
245 }
246
247 $this->products = new WCML_Products( $this, $sitepress, null, $wpdb );
248 $this->products->add_hooks();
249 $this->gateways = new WCML_WC_Gateways( $this, $sitepress );
250 $this->gateways->add_hooks();
251 $this->cart->add_hooks();
252
253 WCML_Install::initialize( $this, $sitepress );
254
255 WCML_Resources::set_up_resources( $this, $sitepress );
256 WCML_Resources::add_hooks();
257
258 return true;
259 }
260
261 public function get_settings() {
262 $defaults = [
263 \WCML_Downloadable_Products::SYNC_MODE_SETTING_KEY => (int) \WCML_Downloadable_Products::SYNC_MODE_SETTING_AUTO,
264 'is_term_order_synced' => 0,
265 'enable_multi_currency' => WCML_MULTI_CURRENCIES_DISABLED,
266 'dismiss_doc_main' => 0,
267 'trnsl_interface' => 1,
268 'currency_options' => [],
269 'currency_switcher_product_visibility' => 1,
270 'dismiss_tm_warning' => 0,
271 'dismiss_cart_warning' => 0,
272 'cart_sync' => [
273 'lang_switch' => WCML_CART_SYNC,
274 'currency_switch' => WCML_CART_SYNC,
275 ],
276 ];
277
278 if ( empty( $this->settings ) ) {
279 $this->settings = get_option( '_wcml_settings', [] );
280 }
281
282 foreach ( $defaults as $key => $value ) {
283 if ( ! isset( $this->settings[ $key ] ) ) {
284 $this->settings[ $key ] = $value;
285 }
286 }
287
288 return $this->settings;
289 }
290
291 public function get_setting( $key, $fallback = null ) {
292 if ( array_key_exists( $key, $this->settings ) ) {
293 return $this->settings[ $key ];
294 }
295 return get_option( 'wcml_' . $key, $fallback );
296 }
297
298 public function update_settings( $settings = null ) {
299 if ( ! is_null( $settings ) ) {
300 $this->settings = $settings;
301 }
302 update_option( '_wcml_settings', $this->settings );
303 }
304
305 public function update_setting( $key, $value, $autoload = false ) {
306 if ( array_key_exists( $key, $this->settings ) ) {
307 $this->settings [ $key ] = $value;
308 $this->update_settings( $this->settings );
309 } else {
310 update_option( 'wcml_' . $key, $value, $autoload );
311 }
312 }
313
314 public function get_stable_wc_version() {
315 $file = WC()->plugin_path() . '/readme.txt';
316 $values = file( $file );
317 $wc_info = explode( ':', $values[5] );
318 $version = '';
319
320 if ( 'Stable tag' === $wc_info[0] ) {
321 $version = trim( $wc_info[1] );
322 } else {
323 foreach ( $values as $value ) {
324 $wc_info = explode( ':', $value );
325
326 if ( 'Stable tag' === $wc_info[0] ) {
327 $version = trim( $wc_info[1] );
328 }
329 }
330 }
331
332 return $version;
333 }
334
335 public function get_supported_wp_version() {
336 $file = WCML_PLUGIN_PATH . '/readme.txt';
337
338 $values = file( $file );
339
340 $version = explode( ':', $values[6] );
341
342 if ( 'Tested up to' === $version[0] ) {
343 return $version[1];
344 }
345
346 foreach ( $values as $value ) {
347 $version = explode( ':', $value );
348
349 if ( 'Tested up to' === $version[0] ) {
350 return $version[1];
351 }
352 }
353
354 return '';
355 }
356
357 public function get_wc_query_vars() {
358 return WooCommerce::instance()->query->query_vars;
359 }
360
361 public function get_multi_currency() {
362 if ( ! ( $this->multi_currency instanceof WCML_Multi_Currency ) ) {
363 $this->multi_currency = make( WCML_Multi_Currency::class );
364 }
365 return $this->multi_currency;
366 }
367
368 public function version() {
369 return get_option( '_wcml_version' );
370 }
371
372 public function plugin_url() {
373 return WCML_PLUGIN_URL;
374 }
375
376 public function js_min_suffix() {
377 return WCML_JS_MIN;
378 }
379
380 public function is_wpml_prior_4_2() {
381 $sitepress = getSitePress();
382
383 return $sitepress->get_wp_api()->version_compare( $this->get_constant( 'ICL_SITEPRESS_VERSION' ), '4.2.0', '<' ) ||
384 $sitepress->get_wp_api()->version_compare( $this->get_constant( 'WPML_TM_VERSION' ), '2.8.0', '<' );
385 }
386
387 private function get_constant( $name ) {
388 return getSitePress()->get_wp_api()->constant( $name );
389 }
390 }
391