A
A
artegion2018-02-03 17:50:41
WordPress
artegion, 2018-02-03 17:50:41

Wordpress - change content when choosing a city?

Hello! I need help, it is necessary to implement a choice of cities on the Wordpress website (6 in total), when choosing a city, the information changes. The phone number of the selected city is in the header , the address of the selected city is in the footer . Well, so that when surfing the site, the value was preserved and it was not necessary to make a constant choice of the city on each page.
The use of Geo plugins disappears, and the option of creating networks and subdomains also disappears, since in all cities the content (prices, text, numbers) remains static ... Please help, which plugins can be used to implement this? Or point me in the right direction!
YaG leads to Geo plugins, in my region these plugins do not work... there was a question on the Toaster, but there is no solution and implementation! Who faced or who has any thoughts ?! I will be very grateful!
Thank you in advance...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Igor Vorotnev, 2018-02-03
@artegion

Well, it’s unlikely that anyone will do the implementation for you here - the task is more or less voluminous and more likely for freelance than Toaster. The logic is generally simple:
- Make a select with cities
- Save the choice in a cookie on the client
- When you enter, you get a cookie
- Based on the value in the cookie, load the necessary data
- Store the data itself as convenient, most likely it will be the Options API. To do this, create your own settings page, it contains fields for each city. You save the values ​​with the city ID, which will be stored in the cookie (or better, as a serialized array in one field).
Disadvantages of the approach without geolocation:
- the user needs to select the city by hand
- cookies are not very long-term storage, they are often cleaned, so after cleaning the choice must be made again.
For registered and authorized users, you can add an additional feature - save their choice in wp_usermeta for their user, then there will be no dependence on cookies. Ideally, of course, it is better to use both - this will save the user's choice even if he is logged out of the account. It still needs additional logic to compare and process the values ​​in the cookie and in the database (because the user could change the choice in the cookie when he was not authorized). Plus, you need to update the cookie sometime.
Geolocation will not solve the issue completely, I would advise you to combine it with cookies anyway. Geolocation will only allow you not to force the user to select manually. And in most cases, when his location matches the city he needs, he will never have to change anything.

R
Roman Kusty, 2021-10-07
@roman_tlt

The free plugin WT Geotargeting will help you . With it, you can implement a city selection on the site and display various information with reference to the city.
When choosing a city, the value is stored in the cookie and when you move through the pages, or a subsequent visit, you do not need to select the city again.
The plugin has an extended paid version, the capabilities of which can be found on the official website .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question