forked from qTranslate-Team/woocommerce-qtranslate-x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
woocommerce-qtranslate-x.php
48 lines (45 loc) · 1.89 KB
/
woocommerce-qtranslate-x.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* Plugin Name: WooCommerce & qTranslate-X
* Plugin URI: https://wordpress.org/plugins/woocommerce-qtranslate-x
* Description: Enables multilingual framework for plugin "WooCommerce".
* Version: 1.4
* Author: qTranslate Team
* Author URI: http://qtranslatexteam.wordpress.com/about
* License: GPL2
* Tags: multilingual, multi, language, translation, qTranslate-X, WooCommerce
* Author e-mail: [email protected]
*/
if(!defined('ABSPATH'))exit;
define('QWC_VERSION','1.4');
function qwc_init_language($url_info)
{
if($url_info['doing_front_end']) {
require_once(dirname(__FILE__)."/qwc-front.php");
}else{
require_once(dirname(__FILE__)."/qwc-admin.php");
}
}
add_action('qtranslate_init_language','qwc_init_language');
/**
* Dealing with mini-cart cache in internal browser storage.
* Prevents language switch on wc-ajax calls.
* This is needed when user has a few tabs in browser open in different languages, and mini-cart is being refreshed in all of them with wc-ajax calls. This way mini-cart will be shown on all tabs with the same language, which user set the most recently. This makes better sense comparing to showing mini-cart in the language of last change of cart.
* @param array $url_info qtx variable.
* @return array possibly modified $url_info.
* @since 1.4
*/
function qwc_detect_language($url_info)
{
if( isset($url_info['cookie_lang_front']) && $url_info['cookie_lang_front'] != $url_info['language']){
//language is about to switch
if ( ! empty( $_GET['wc-ajax'] ) && !empty($url_info['doing_front_end']) ){
//do not switch language on wc-ajax calls, rather stay with previously set language stored in cookies.
$url_info['language'] = $url_info['cookie_lang_front'];
$url_info['lang_wc-ajax'] = $url_info['language'];
$url_info['doredirect'] = 'wc-ajax';
}
}
return $url_info;
}
add_filter( 'qtranslate_detect_language', 'qwc_detect_language', 5 );