Skip Navigation

[Resolved] Customizing product frontend adding Map with address custom fields

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

Problem: In my Product post template, I would like to show a map with a marker at an address set by a custom field. If the address field has no value, I would like to hide the map.

Solution: Use conditionals testing the value of the address custom field to show content conditionally. Use the wpv-map-render and wpv-map-marker shortcodes to display the map and marker.

[wpv-conditional if="( $(wpcf-fermata) ne '' )"]
[wpv-map-render map_id="tssupp-test-map" map_width="500" map_height="250"][/wpv-map-render]
[wpv-map-marker map_id='tssupp-test-map' marker_id='tssupp-test-program-marker' marker_field='wpcf-fermata'][/wpv-map-marker]
[/wpv-conditional]

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/maps/maps-shortcodes/

This support ticket is created 4 years 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 2 voices.

Last updated by marcoB-12 4 years ago.

Assisted by: Christian Cox.

Author
Posts
#2067993

Hi,
I'm trying to customize product on my development site way4go.com.
My goal is to add Google Maps on product frontend (in the description) using Address custom fields in the product backend and wrapping shortcode in the product description.
But it doesn't works..in the product frontend appears only the address string or the geo coordinates and not the map.
The example is hidden link
Could you help me please?
If you know any other method to insert custom fields address Maps in the product layout could you suggest me please.
I think the theme I choose (Rehub) is not fully compatible with Gutemberg block and there are some issue using Toolset block. Do you think the same?

Any suggestions is much appreciated.
Thank you.
Marco

#2068227

My goal is to add Google Maps on product frontend (in the description) using Address custom fields in the product backend and wrapping shortcode in the product description...But it doesn't works..in the product frontend appears only the address string or the geo coordinates and not the map.
Hello, I'm not famliar with this specific theme but I can investigate the problem here and try to find the best solution. I was trying to find a Product post where I can see the problem on the front-end of the site, but I'm not sure where to look. The link you shared is a wp-admin link: hidden link
I checked a couple of Prodotto posts but the templates are quite different and I see a functioning map in the Destinazione section of the Tenerife post:
hidden link
hidden link
So I'm a bit confused. It might be faster for me to log into wp-admin to understand things better. If that is okay, please provide login credentials in the private reply fields here. I will take a closer look.

#2069387

Okay thank you for that information. I'm looking at this post now:
hidden link

Post editor page:
hidden link

Here is the original code from the Description section:

[types field='fermata' separator=', '][/types]
[wpv-conditional if="( $(wpcf-map-address) ne '' )"]	 
[wpv-map-marker map_id='programs-map' marker_id='program-marker' marker_field='wpcf-map-address'][/wpv-map-marker]	 
[/wpv-conditional]

Here is the updated code:

[types field='fermata' separator=', '][/types]

[wpv-conditional if="( $(wpcf-fermata) ne '' )"]
[wpv-map-render map_id="tssupp-test-map" map_width="500" map_height="250"][/wpv-map-render]
[wpv-map-marker map_id='tssupp-test-map' marker_id='tssupp-test-program-marker' marker_field='wpcf-fermata'][/wpv-map-marker]
[/wpv-conditional]

You can see I changed the conditional to test the if the fermata field has any values. The conditional was originally set to test a field map-address, but that field does seem to exist on your site. This is one reason why you did not see any map on the front-end. The other reason is the wpv-map-render shortcode was not included. Both wpv-map-render and wpv-map-marker are required to show a map and a marker on the map. I added an example wpv-map-render shortcode here so you can see how it works. Notice the map_id attributes are identical for the two shortcodes. Another important attribute is marker_id. That should be a unique value. The marker_field attribute tells the marker to look for addresses in the fermata custom field. In the current post, the fermata custom field has multiple values, so multiple markers are shown on the map.

Let me know if you have questions about this. We have documentation for these shortcodes here: https://toolset.com/documentation/programmer-reference/maps/maps-shortcodes/

#2070255

Thank you, Christian!
Very clear explanation, I will study the documentation starting from your code.
Marco