This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 7 replies, has 3 voices.

Last updated by Andreas W. 4 months, 2 weeks ago.

Assigned support staff: Andreas W..

Author Posts
May 27, 2019 at 8:54 am #3894869

turgutP

Hi,

We have an extraordinary situation, I know redirect to language due to geoip reading is no more exist. But we need to check woocommerce geoip reading and change the language in every page.

That will occur only in one county. If you are in Turkey, language must be Turkish, not only in home page, but also all pages including woocommerce pages.

How can I do that with woocommerce geoip reading and wordpress hooks, I only need some code snippets if possible. Thank you.

May 27, 2019 at 3:43 pm #3899289

Bruno Kos
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hi,

Thank you for contacting WPML support!

I am not sure entirely in the scenario you're after, but does this answer your question?
https://wpml.org/documentation/getting-started-guide/language-setup/automatic-redirect-based-on-browser-language/

Perhaps also this:
https://wpml.org/forums/topic/currency-switcher-woocommerce/#post-1276995

Regards,
Bruno Kos

May 30, 2019 at 8:34 am #3921365

turgutP

OK, first thanks. Let me clear it for you.

I need the hook which @mattf-5 use for himself: https://wpml.org/forums/topic/trying-to-set-language-in-a-php-function/

After, I'm going to find a way to get location from WC_Geolocation(woocommerce class) class and try to get the feature back, which is changing the language due to location.

May 30, 2019 at 2:46 pm #3923989

Andreas W.
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello,

Bruno is sadly not at office today, which for I am glad to assist you.

The WPML Hooks reference can be found here:
https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/

Anyhow, don't you think it might be easier to use aplugin to achieve the redirection?

A list of of plugins that have been tested with WPML can be found here:
https://wpml.org/documentation/plugins-compatibility/?wpv_view_count=119945&dev=0&wpv-plugin-functionality=0&wpv_post_search=&wpv_filter_submit=Search

Possibly this plugin might fit your needs?
https://wpml.org/plugin/123-wpml-redirect-based-ip-country/

Let me know if you do have further questions.
Kind regards
Andreas

May 31, 2019 at 7:21 am #3928247

turgutP

Hi Andreas,

Thanks for the answer.

Unfortunatelly, https://wpml.org/plugin/123-wpml-redirect-based-ip-country/ plugin is not working well. Addition to that, using cache plugins is a must when you use WPML. That plugin doesnt work with caching as the author says.

So I need to write some codes for checking location from ip. Its not easy. I'm going to do some research today, if I can find something, I'll inform you and it will be usefull for other customers.

May 31, 2019 at 3:03 pm #3931471

Andreas W.
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello,

Thank you for your message.

This plugin should to the job as well. You can set Custom filter – redirect based on your own WordPress filter and redirect by IP address – redirect if the client IP address matches.

https://wordpress.org/plugins/redirection/

I am not sure how it behaves with Cache Plugins but maybe youwould like to give it a try?

Kind regards
Andreas

May 31, 2019 at 3:27 pm #3931657

turgutP

Hi,

I handleded the situation with another plugin. It's geoip detection works well and I edited one of its php files named location.php. In every and refresh, plugin runs location.php and that plugin is compatible with w3-cache in pro version, I didn't try it yet.

Attention: this code is only a prototype, if all tests pass, I'll tidy it up and make some corrections. I don't have any wordpress filter knowledge or something.

And this is my code:

//$currency_detected came from plugin called woo-multi-currency that uses geoip from woocommerce
//TRY = Turkish Lira
//This code forces to redirect Turkish pages and changes language to TR when you are IN Turkey by geoip 
if ( $currency_detected == 'TRY')
{

        do_action( 'wpml_switch_language', 'tr' );								
	if(get_locale() == 'en_US' && !is_admin())
        {
		wp_redirect( apply_filters( 'wpml_permalink', '<em><u>hidden link</u></em>'.$_SERVER['HTTP_HOST'] .$_SERVER['REQUEST_URI'], 'tr', true ));
		exit;
        }
}

Some of my notes are:
-Can't find a function to get full url, I'll handle it later
-apply_filters( 'wpml_permalink', $url, lang_code, true ) doesn't work without http or https. Also it doesn't work with default shop page url and home url(www.example.com to hidden link). I needed to handle some urls with additional if conditions.
-I've read about wpml_permalink has performance issues but I can't find any working alternative.

May 31, 2019 at 4:18 pm #3932023

Andreas W.
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello,

Actually, it should be the function realted to the mentioned filter in your example:

https://wpml.org/wpml-hook/wpml_permalink/

The complete WPML Hook reference can be found here.
https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/#hook-662194

I have to admint that I am myself not much familiar yet when it comes to apply Actions and Filters, but I can offer you to consult our second tier support in order you run into any issues.

One additional question about your request. I am not understanding correctly I think. Does your website not redirect users automatically to the respective WooCommerce pages? Example: Turkish user anter turkish homepage and clicks Shop. does he get forwarded to the English shop? if so, this is not any default bahvior as with WPML the redirect should by default lead to the same language directory. Did you check if any Store URLs are translated correctly at WooCommerce -> WooCommerce Multilingual -> Store URLs.

Further the option for multiple currencies lets you set specific currencies as default for specific languages and you will also be able to exclude currencies for specific languages.

Could you please calrif a little further what is what you are expereicning on the site and what it the result that you are expecting?
I would like to request temporary access (wp-admin and FTP) to your site to take a better look at the issue. It would be better to a testing site where the issue is replicated.

You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.

Maybe I'll need to replicate your site locally. For this, I’ll need to temporarily install a plugin called “Duplicator” on your site. This will allow me to create a copy of your site and your content. Once the problem is resolved I will delete the local site. Let me know if this is ok with you.

IMPORTANT

Please make a backup of site files and database before providing us access.
If you do not see the wp-admin/FTP fields this means your post & website login details will be made PUBLIC. DO NOT post your website details unless you see the required wp-admin/FTP fields. If you do not, please ask me to enable the private box. The private box looks like this:
hidden link

Kind regards
Andreas

The topic ‘[Closed] Forcing language due to woocommerce geoip reading’ is closed to new replies.