Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

Commit 701f5e2

Browse files
committed
fix update cart when switched language in WooCommerce
add action on switched language
1 parent df2ffc6 commit 701f5e2

File tree

4 files changed

+57
-6
lines changed

4 files changed

+57
-6
lines changed

core/class-wpm-setup.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,9 @@ public function redirect_to_user_language() {
415415

416416
if ( ! is_admin() && ! defined( 'WP_CLI' ) ) {
417417

418-
if ( ! isset( $_COOKIE['wpm_was_here'] ) ) {
418+
if ( ! isset( $_COOKIE['wpm_language'] ) ) {
419419

420-
wpm_setcookie( 'wpm_was_here', true, time() + YEAR_IN_SECONDS );
420+
wpm_setcookie( 'wpm_language', $this->user_language, time() + YEAR_IN_SECONDS );
421421
$redirect_to_browser_language = apply_filters( 'wpm_redirect_to_browser_language', true );
422422

423423
if ( $redirect_to_browser_language ) {
@@ -446,7 +446,12 @@ public function redirect_to_user_language() {
446446
exit;
447447
}
448448
}
449-
}
449+
} else {
450+
if ( $_COOKIE['wpm_language'] != $this->user_language ) {
451+
do_action( 'wpm_changed_language' );
452+
wpm_setcookie( 'wpm_language', $this->user_language, time() + YEAR_IN_SECONDS );
453+
}
454+
} // End if().
450455
} // End if().
451456
}
452457

core/vendor/class-wpm-woocommerce.php

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Class for capability with WooCommerce
4+
*/
5+
6+
namespace WPM\Core\Vendor;
7+
8+
if ( ! defined( 'ABSPATH' ) ) {
9+
exit;
10+
}
11+
12+
if ( ! defined( 'WC_VERSION' ) ) {
13+
return;
14+
}
15+
16+
/**
17+
* Class WPM_WooCommerce
18+
* @package WPM\Core\Vendor
19+
* @category Vendor
20+
* @author VaLeXaR
21+
*/
22+
class WPM_WooCommerce {
23+
24+
/**
25+
* WPM_WooCommerce constructor.
26+
*/
27+
public function __construct() {
28+
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_js_frontend' ) );
29+
}
30+
31+
public function enqueue_js_frontend() {
32+
if ( did_action( 'wpm_changed_language' ) ) {
33+
wp_add_inline_script( 'wc-cart-fragments', "
34+
jQuery( function ( $ ) {
35+
$( document.body ).trigger( 'wc_fragment_refresh' );
36+
});
37+
");
38+
}
39+
}
40+
}
41+
42+
new WPM_WooCommerce();

readme.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Contributors: valexar
44
Tags: localization, multilanguage, multilingual, translation, multilang
55
Requires at least: 4.7
66
Tested up to: 4.8.1
7-
Stable tag: 1.5.4
7+
Stable tag: 1.5.5
88
License: GPLv2 or later
99
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1010

@@ -139,6 +139,10 @@ Compatible with multisite not tested.
139139

140140
== Changelog ==
141141

142+
= 1.5.5 =
143+
* fix update cart when switched language in WooCommerce
144+
* add action on switched language
145+
142146
= 1.5.4 =
143147
* fix save acf fields
144148
* fix translate strings with zero

wp-multilang.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
99
* Text Domain: wpm
1010
* Domain Path: /languages
11-
* Version: 1.5.4
11+
* Version: 1.5.5
1212
*
1313
* @package WPM
1414
* @category Core
@@ -42,7 +42,7 @@ final class WP_Multilang {
4242
*
4343
* @var string
4444
*/
45-
public $version = '1.5.4';
45+
public $version = '1.5.5';
4646

4747
/**
4848
* The single instance of the class.

0 commit comments

Comments
 (0)