@@ -50,7 +50,7 @@ class Dokan_WPML {
50
50
51
51
/*
52
52
* WordPress Endpoints text domain
53
- *
53
+ *
54
54
* @var string
55
55
*/
56
56
public $ wp_endpoints = 'WP Endpoints ' ;
@@ -87,6 +87,8 @@ public function __construct() {
87
87
add_filter ( 'dokan_get_current_page_id ' , [ $ this , 'dokan_set_current_page_id ' ] );
88
88
add_filter ( 'dokan_get_dashboard_nav ' , [ $ this , 'replace_dokan_dashboard_nav_key ' ] );
89
89
add_action ( 'wp_head ' , [ $ this , 'dokan_wpml_remove_fix_fallback_links ' ] );
90
+
91
+ add_action ( 'dokan_store_page_query_filter ' , [ $ this , 'load_store_page_language_switcher_filter ' ], 10 , 2 );
90
92
}
91
93
92
94
/**
@@ -200,7 +202,7 @@ function load_translated_url( $url, $name ) {
200
202
public function replace_dokan_dashboard_nav_key ( $ urls ) {
201
203
$ current_lang = apply_filters ( 'wpml_current_language ' , NULL );
202
204
$ new_urls = $ urls ;
203
-
205
+
204
206
foreach ( $ urls as $ get_key => $ item ) {
205
207
$ new_key = apply_filters ( 'wpml_translate_single_string ' , $ get_key , $ this ->wp_endpoints , $ get_key , $ current_lang );
206
208
if ( $ get_key != $ new_key ) {
@@ -425,10 +427,27 @@ public function dokan_wpml_remove_fix_fallback_links() {
425
427
dokan_remove_hook_for_anonymous_class ( 'the_content ' , 'WPML_Fix_Links_In_Display_As_Translated_Content ' , 'fix_fallback_links ' , 99 );
426
428
}
427
429
430
+ /**
431
+ * @param \WP_query $query
432
+ * @param array $store_info
433
+ */
434
+ public function load_store_page_language_switcher_filter ( $ query , $ store_info ) {
435
+ // This needs to be improved, I am probably missing a smarter way to get the current store URL.
436
+ // Perhaps the current store URL could be included in the $store_info (2nd argument).
437
+ $ custom_store_url = dokan_get_option ( 'custom_store_url ' , 'dokan_general ' , 'store ' );
438
+ $ store_slug = $ query ->get ( $ custom_store_url );
439
+ $ store_user = get_user_by ( 'slug ' , $ store_slug );
440
+ $ store_url = dokan_get_store_url ( $ store_user ->ID );
441
+
442
+ add_filter ( 'wpml_ls_language_url ' , function ( $ url , $ data ) use ( $ store_url ) {
443
+ return apply_filters ( 'wpml_permalink ' , $ store_url , $ data ['code ' ] );
444
+ }, 10 , 2 );
445
+ }
446
+
428
447
} // Dokan_WPML
429
448
430
449
function dokan_load_wpml () {
431
450
$ dokan_wpml = Dokan_WPML::init ();
432
451
}
433
452
434
- dokan_load_wpml ();
453
+ dokan_load_wpml ();
0 commit comments