Skip to content

Commit ceb0041

Browse files
authored
Merge pull request #14 from OnTheGoSystems/issue-9
Fix the language switcher URLs on the store page
2 parents 8ce67cf + c243e07 commit ceb0041

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

dokan-wpml.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Dokan_WPML {
5050

5151
/*
5252
* WordPress Endpoints text domain
53-
*
53+
*
5454
* @var string
5555
*/
5656
public $wp_endpoints = 'WP Endpoints';
@@ -87,6 +87,8 @@ public function __construct() {
8787
add_filter( 'dokan_get_current_page_id', [ $this, 'dokan_set_current_page_id' ] );
8888
add_filter( 'dokan_get_dashboard_nav', [ $this, 'replace_dokan_dashboard_nav_key' ] );
8989
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 );
9092
}
9193

9294
/**
@@ -200,7 +202,7 @@ function load_translated_url( $url, $name ) {
200202
public function replace_dokan_dashboard_nav_key( $urls ) {
201203
$current_lang = apply_filters( 'wpml_current_language', NULL );
202204
$new_urls = $urls;
203-
205+
204206
foreach ( $urls as $get_key => $item ) {
205207
$new_key = apply_filters( 'wpml_translate_single_string', $get_key, $this->wp_endpoints, $get_key, $current_lang );
206208
if ( $get_key != $new_key ) {
@@ -425,10 +427,27 @@ public function dokan_wpml_remove_fix_fallback_links() {
425427
dokan_remove_hook_for_anonymous_class( 'the_content', 'WPML_Fix_Links_In_Display_As_Translated_Content', 'fix_fallback_links', 99 );
426428
}
427429

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+
428447
} // Dokan_WPML
429448

430449
function dokan_load_wpml() {
431450
$dokan_wpml = Dokan_WPML::init();
432451
}
433452

434-
dokan_load_wpml();
453+
dokan_load_wpml();

0 commit comments

Comments
 (0)