[I am using the shared code here.
I added a Login and Register link to the menu.]
(Login and Register in woocommerce site)
But I can't check language urls.
www.example.com/tr/
www.example.com/en/
www.example.com/ar/
The code that ı use :
function so_loginout_menu_links( $items, $args ) {
if ( $args->theme_location == 'primary' && function_exists('is_woocommerce') ) {
if (is_user_logged_in()) {
$items .= '<li><a href="'. site_url('/my-account/customer-logout') .'">'. __("Log Out") .'</a></li>';
$items .= '<li><a href="'. get_permalink( get_option('woocommerce_myaccount_page_id') ).'">'. __("My Account") .'</a></li>';
} else {
$items .= '<li><a href="'. site_url('/my-account') .'">'. __("Log In") .'</a></li>';
$items .= '<li><a href="'. site_url('/my-account').'">'. __("Register") .'</a></li>';
}
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'so_loginout_menu_links', 10, 2 );
site_url = www.example.com
I want someone who is in English to come to www.example.com/en/my-account when my account link is clicked.
This may be in a different language.
There are currently 3 languages in my site.
How do I control?
Sorry for late reply. I updated it this way.
function so_loginout_menu_links( $items, $args ) {
if ( $args->theme_location == 'primary' && function_exists('is_woocommerce') ) {
if (is_user_logged_in()) {
$items .= '<li><a href="'. pll_home_url().('/my-account/customer-logout') .'">'. __("Log Out") .'</a></li>';
$items .= '<li><a href="'. get_permalink( get_option('woocommerce_myaccount_page_id') ).'">'. __("My Account") .'</a></li>';
} else {
$items .= '<li><a href="'. pll_home_url().('/my-account/') .'">'. __("Log In") .'</a></li>';
$items .= '<li><a href="'. pll_home_url().('/my-account/').'">'. __("Register") .'</a></li>';
}
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'so_loginout_menu_links', 10, 2 );
My urls are different in all languages.
For example:
My Account URL
TR: www.example.com/tr/hesabim
EN: www.example.com/my-account
AR: www.example.com/ar/my-account-ar
When pll_home_url is added.
That's the links.
www.example.com/tr/my-account
www.example.com/ar/my-account
This leads to the English page again.