I’m trying to build in a Location map on the Vendor pages (to pull in a small map like on Requests and Listings) and I think I’m pretty close but I’m not sure what the attribute (or meta key) value is for the Vendor Location. I’m using “location” currently and I’ve tried “hp_location” and “hp_vendor_location” - none of which worked. Is there a place to find all of these values listed somewhere? And more specificially, what should Vendor Location be?
Here’s my code so far (creating a shortcode for the display portion):
function custom_vendor_location_map_shortcode($atts) {
if (!function_exists('hivepress')) {
return '';
}
$atts = shortcode_atts([
'vendor_id' => null,
], $atts, 'vendor_location_map');
$vendor = null;
if ($atts['vendor_id']) {
$vendor = hivepress()->vendor->get_vendor((int)$atts['vendor_id']);
} else {
$vendor = hivepress()->request->get_context('vendor');
}
if (!$vendor || !$vendor->get_id()) {
return '<p>No vendor found.</p>';
}
// Try common meta key for location attribute - have to figure out what this value actually needs to be... JJ
$location = $vendor->get_meta('location');
if (!$location) {
return '<p>No location set for this vendor.</p>';
}
ob_start();
echo '<div class="vendor-location-map" style="margin-top: 20px;">';
echo hivepress()->template->get_block('location_map', [
'location' => $location,
'zoom' => 14,
'height' => 300,
]);
echo '</div>';
return ob_get_clean();
}
add_shortcode('vendor_location_map', 'custom_vendor_location_map_shortcode');
I’m not HivePress staff, but from reading a lot of forum posts on here I believe there’s hidden fields of ‘longitude’ and ‘latitude’.
If you search the forum, you’ll likely find another topic mentioning them. Hopefully, you’ll be able to find the exact terms you’re looking for, and tweak them as needed!
If you manage to achieve the functionality, it would be nice if you could share your code with the community for anyone else trying to put something similar together themselves!
Thanks. That’s a bit different then what I’m trying to do. I’m literally just trying to show the same type of location map we’d have in Individual Listings or Requests but on a single Vendor page showing the Vendor’s location. Vendors all have locations so it should be more straight-forward than it appears to be.