Archived topic
Woocommerce search in menu with WPML goes to default language
3 replies · Started by John MacKenzie on September 9, 2020
hi guys i found this article on wpml and tried this (in child theme override)
https://wpml.org/forums/topic/problem-with-the-search-wrong-language-in-the-results/
but it didnt do anything.
when searching in english in the menu search, it defaults back to french.
how can we solve this?
Thanks!
Hi there,
You should do something like this, instead:
add_filter( 'generate_navigation_search_output', function() {
return sprintf( // WPCS: XSS ok, sanitization ok.
'<form method="get" class="search-form navigation-search" action="%1$s">
<input type="search" class="search-field" value="%2$s" name="s" title="%3$s" />
<input type="hidden" name="lang" value="%4$s" />
</form>',
esc_url( home_url( '/' ) ),
esc_attr( get_search_query() ),
esc_attr_x( 'Search', 'label', 'generatepress' ),
apply_filters( 'wpml_current_language', NULL )
);
} );
It should be added to your functions.php file.
Hope this helps!
Hi Tom thanks!
i added that but it didnt appear to make any difference?
John
That code is simply a better method of what WPML suggested. I'm afraid I'm not aware of the inner-working of their code, so I'm not sure if it will actually fix the issue. It may be worth getting in touch with their support to see if something has changed.