Skip Navigation

[Resolved] Extract and compare City from entire Toolset Address field value

This thread is resolved. Here is a description of the problem and solution.

Problem:
How can I compare the Toolset Address Field value (the entire address) to a single City value or ZIP code?

Solution:
It's not possible to extract a city from a Google Maps address using Toolset.

What you can do is compare the exact address, or, use some custom code to manipulate/read the address field differently.

Another - and the suggested one - approach is to use a custom field where you can add the city.
Both in the product and the user.

Then, you can compare those 2 fields.

This support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 3 replies, has 3 voices.

Last updated by stephaneL-3 6 years, 9 months ago.

Assisted by: Beda.

Author
Posts
#617635

Hi there

I have added an Address field in the woocommerce PRODUCT content type.
I have also added an Address field to the USER profile.

I want to be able to compare the two address fields to see if the User is from the same City the product is from. If it is the same the user can buy the product, if not they cannot. I am happy to simply just hide the add to cart button using CSS if the city does not match.

Im trying to set this up but cant figure it out. Would you be able to kindly assist me in the right direction?

Much appreciated

Regards,

Pouya

#617864

It's not possible to extract a city from a Google Maps address using Toolset.
What you can do is compare the exact address, or, use some custom code to manipulate/read the address field differently.

Another - and the suggested one - approach is to use a custom field where you can add the city.
Both in the product and the user.

Then, you can compare those 2 fields.

#618109

thanks a lot man
i fixed it your way, brilliant idea
i then used the following code to check the two fields and it works 🙂

[wpv-conditional if="( $(wpcf-product-state) eq '[types usermeta="user-state" user_current="true" output="raw"][/types]' )"]both values match[/wpv-conditional]
[wpv-conditional if="( $(wpcf-product-state) ne '[types usermeta="user-state" user_current="true" output="raw"][/types]' )"]values do not match[/wpv-conditional]

#1621449

Hi there,

Just checking if this is still not possible to extract the city from an address field.
I have read most thread on this which are dating 2yrs + so I am hoping it is now possible to do this?
I read it was difficult if the coordinates (Lon/Lat) used are not in a city, but I don't mind if it return a null value, I am confident the address that will entered will be in a city in 99.9% of the time, and happy to risk the empty field.

However it seems conter intuitive to ask for an address and then have the user entered the town in a separate field, let alone the problem with mis spelling etc.

I have used other service whee you can indeed extract part of the address and I hope this can be done, it would be useful in so many ways to be able to extract the Country / Town fromt he address. The need of a manual sep field seems a little backward.

Thank you for you rtime
s