Add map block to the vendor page

Hi there,

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');

Cheers,
Jeff

Hey,

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!

I hope this helps!

Cheers,
Chris

1 Like

Hi,

Please try removing this condition in the code hivepress-geolocation/includes/components/class-geolocation.php at master · hivepress/hivepress-geolocation · GitHub If the map starts showing, then you can implement it the same way, insert the same map block via the hivepress/v1/templates/vendor_view_page filter hook.

The location is stored in 3 meta fields: hp_location (text), hp_latitude (latitude), hp_longitude (longitude).

Hope this helps

Unfortunately, removing that condition didn’t solve it. I’ll look at pulling those meta fields into my shortcode and see if that helps.

Hey @lmg-jjones,

I’m not sure if you’ve seen this topic, but it might be useful:

Cheers,
Chris :victory_hand:

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.

Please try this code snippet as a temporary fix:

add_filter(
	'hivepress/v1/templates/vendor_view_page',
	function ( $template ) {
		$map = ( new \HivePress\Blocks\Listing_Map(
			[
				'model'      => 'vendor',
				'attributes' => [
					'class' => [ 'hp-vendor__map', 'hp-listing__map', 'widget' ],
				],

			]
		) )->render();

		return hivepress()->template->merge_blocks(
			$template,
			[
				'page_sidebar' => [
					'blocks' => [
						'vendor_map' => [
							'type'    => 'content',
							'content' => $map,
							'_order'  => 25,

						],
					],
				],
			]
		);
	},
	1000
);

We’ll also add map support to the vendor pages in the next update.

1 Like

Thanks so much @ihor . That worked perfectly.

Would there be a similar way to allow Galleries for Vendors (like you have available for Listings)?