Skip to content
This repository has been archived by the owner on Mar 17, 2022. It is now read-only.

broken language switcher links on search page #566

Open
am3000 opened this issue Nov 18, 2021 · 1 comment
Open

broken language switcher links on search page #566

am3000 opened this issue Nov 18, 2021 · 1 comment

Comments

@am3000
Copy link

am3000 commented Nov 18, 2021

Hey there,

on the search page the language switcher links are broken.

Also see this support question from another user: https://wordpress.org/support/topic/search-page-error-2/

I investigated and saw that it is caused by Pages::translateShopUrl()

I suggest to add

if ( is_search() ) {
            return $result;
        }

after $result = $url;

to fix this outside of the plugin this workaround should do it:

// fix an error introduced by woo-poly-integration in Pages::translateShopUrl()
add_filter('pll_get_archive_url', 'fix_language_switcher_url_error_1', 9, 2);
add_filter('pll_get_archive_url', 'fix_language_switcher_url_error_2', 11, 2);
function fix_language_switcher_url_error_1($url, $language){
    global $ARCHIVE_URL_BEFORE_WOO_POLY_HOOK;
    $ARCHIVE_URL_BEFORE_WOO_POLY_HOOK = $url;
    return $url;
}
function fix_language_switcher_url_error_2($url, $language){
    global $ARCHIVE_URL_BEFORE_WOO_POLY_HOOK;
    if(is_search()){
        $domain = get_option('siteurl');
        if(stripos($url, $domain)===false){
            $url = $ARCHIVE_URL_BEFORE_WOO_POLY_HOOK;
        }
    }
    return $url;
}
@tekisei
Copy link

tekisei commented Feb 24, 2022

I had a similar problem with the language switcher on the non-default language Woocommerce shop page only.

The switcher leading to the default language shop pointed to "http://shop/".

Adding the below code in the function translateShopUrl() in src/Hyyan/WPI/Pages.php will fix the issue.

if ( is_shop() ) {
            return $result;
        }

Woocommerce 5.9.0, Hyyan 1.5.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants