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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 / inc / class-wcml-cart-switch-lang-functions.php
woocommerce-multilingual / inc Last commit date
admin-menus 4 weeks ago currencies 4 weeks ago template-classes 4 weeks ago translation-editor 4 weeks ago class-wcml-ajax-setup.php 4 weeks ago class-wcml-attributes.php 4 weeks ago class-wcml-capabilities.php 4 weeks ago class-wcml-cart-removed-items-widget.php 1 year ago class-wcml-cart-switch-lang-functions.php 4 weeks ago class-wcml-cart-sync-warnings.php 4 weeks ago class-wcml-cart.php 4 weeks ago class-wcml-comments.php 4 weeks ago class-wcml-compatibility.php 4 weeks ago class-wcml-coupons.php 4 weeks ago class-wcml-dependencies.php 4 weeks ago class-wcml-emails.php 4 weeks ago class-wcml-endpoints.php 4 weeks ago class-wcml-install.php 4 weeks ago class-wcml-languages-upgrader.php 4 weeks ago class-wcml-locale.php 4 weeks ago class-wcml-orders.php 4 weeks ago class-wcml-products-screen-options.php 4 weeks ago class-wcml-products.php 4 weeks ago class-wcml-reports.php 4 weeks ago class-wcml-requests.php 4 weeks ago class-wcml-resources.php 4 weeks ago class-wcml-store-pages.php 4 weeks ago class-wcml-terms.php 4 weeks ago class-wcml-tp-support.php 4 weeks ago class-wcml-troubleshooting.php 4 weeks ago class-wcml-upgrade.php 4 weeks ago class-wcml-url-translation.php 4 weeks ago class-wcml-wc-gateways.php 4 weeks ago class-wcml-wc-shipping.php 4 weeks ago class-wcml-wc-strings.php 4 weeks ago class-wcml-widgets.php 4 weeks ago constants.php 4 weeks ago functions-pure.php 4 weeks ago functions.php 4 weeks ago installer-loader.php 4 weeks ago missing-php-functions.php 4 weeks ago wcml-core-functions.php 4 weeks ago wcml-switch-lang-request.php 4 weeks ago
class-wcml-cart-switch-lang-functions.php
107 lines
1 <?php
2
3 use function WPML\Container\make;
4 use WPML\API\Sanitize;
5
6 class WCML_Cart_Switch_Lang_Functions implements \IWPML_Frontend_Action, \IWPML_Backend_Action {
7
8 private $lang_from;
9
10 private $lang_to;
11
12 public function add_hooks() {
13 add_action( 'wp_footer', [ $this, 'wcml_language_switch_dialog' ] );
14 add_action( 'wp_loaded', [ $this, 'wcml_language_force_switch' ] );
15 add_action( 'wcml_user_switch_language', [ $this, 'language_has_switched' ], 10, 2 );
16
17 add_filter( 'woocommerce_product_add_to_cart_url', [ $this, 'remove_force_switch_from_add_to_cart_url' ] );
18 }
19
20 public function remove_force_switch_from_add_to_cart_url( $url ) {
21 $url = str_replace( 'force_switch=1&', '', $url );
22 return $url;
23 }
24
25 public function language_has_switched( $lang_from, $lang_to ) {
26
27 $settings = get_option( '_wcml_settings' );
28
29 if (
30 ! isset( $_GET['force_switch'] ) &&
31 $lang_from !== $lang_to &&
32 ! empty( $settings ) &&
33 WCML_CART_CLEAR === $settings['cart_sync']['lang_switch']
34 ) {
35 $this->lang_from = $lang_from;
36 $this->lang_to = $lang_to;
37 }
38 }
39
40 public function wcml_language_force_switch() {
41 global $woocommerce_wpml, $woocommerce;
42
43 if ( ! wpml_is_ajax() && isset( $_GET['force_switch'] ) && '1' === $_GET['force_switch'] ) {
44 $woocommerce_wpml->cart->empty_cart_if_needed( 'lang_switch' );
45 $woocommerce->session->set( 'wcml_switched_type', 'lang_switch' );
46 }
47 }
48
49 public function wcml_language_switch_dialog() {
50 global $woocommerce_wpml, $sitepress, $post;
51
52 if ( make( WCML_Dependencies::class )->check() ) {
53 $current_url = $this->get_current_url();
54
55 if ( is_shop() ) {
56 $requested_page_id = apply_filters( 'wpml_object_id', wc_get_page_id( 'shop' ), 'post', true, $this->lang_from );
57 } elseif ( isset( $post->ID ) ) {
58 $requested_page_id = apply_filters( 'wpml_object_id', $post->ID, get_post_type( $post->ID ), true, $this->lang_from );
59 }
60
61 if ( isset( $requested_page_id ) ) {
62 $request_url = add_query_arg( 'force_switch', '0', $sitepress->convert_url( get_permalink( $requested_page_id ), $this->lang_from ) );
63 } else {
64 $request_url = $current_url;
65 }
66
67 $cart_for_session = false;
68 if ( WC()->cart instanceof WC_Cart ) {
69 $cart_for_session = WC()->cart->get_cart_for_session();
70 }
71
72 if ( $this->lang_from && $this->lang_to && $request_url && ! empty( $cart_for_session ) ) {
73
74 $force_cart_url = add_query_arg( 'force_switch', '1', $current_url );
75 $active_languages = apply_filters( 'wpml_active_languages', null, null );
76 $dialog_title = __( 'Switching language?', 'woocommerce-multilingual' );
77
78 $confirmation_message = sprintf(
79 /* translators: %s is a language name */
80 __(
81 "You've switched the language and there are items in the cart. If you keep the %s language, the cart will be emptied and you will have to add the items again to the cart.",
82 'woocommerce-multilingual'
83 ),
84 $active_languages[ $this->lang_to ]['translated_name']
85 );
86 /* translators: %s is a language name */
87 $stay_in = sprintf( __( 'Keep %s', 'woocommerce-multilingual' ), $active_languages[ $this->lang_to ]['translated_name'] );
88 /* translators: %s is a language name */
89 $switch_to = sprintf( __( 'Switch back to %s', 'woocommerce-multilingual' ), $active_languages[ $this->lang_from ]['translated_name'] );
90
91 $woocommerce_wpml->cart->cart_alert( $dialog_title, $confirmation_message, $stay_in, $switch_to, $force_cart_url, $request_url, true );
92 }
93 }
94
95 }
96
97 public function get_current_url() {
98 $get_query = $_GET;
99
100 foreach ( $get_query as $index => $item ) {
101 $get_query[ $index ] = Sanitize::string( $item );
102 }
103
104 return home_url( add_query_arg( $get_query ) );
105 }
106 }
107