hyyan / woo-poly-integration

Looking for maintainers! - Wordpress WooCommerce Polylang Integration
https://wordpress.org/plugins-wp/woo-poly-integration/
MIT License
183 stars 66 forks source link

broken language switcher links on search page #566

Open am3000 opened 3 years ago

am3000 commented 3 years ago

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 commented 2 years ago

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