Restrict location view to members


I would like to hide the location map and address in listing pages, so that it is only visible to members (similar to how you can do it for other listing attributes). Is there a way / code snippet to do this?

Thanks in advance

Please try this PHP code snippet

add_filter('hivepress/v1/templates/listings_view_page', 'custom_location_hide', 1000);
add_filter('hivepress/v1/templates/listing_view_page', 'custom_location_hide', 1000);
add_filter('hivepress/v1/templates/listing_view_block', 'custom_location_hide', 1000);

function custom_location_hide($template){
	$membership = \HivePress\Models\Membership::query()->filter(['user' => get_current_user_id()])->get_first();
		return $template;
	hivepress()->template->fetch_blocks($template, ['listing_map', 'listing_location']);
	return $template;

Thanks yevhen. The snippet works in that it does hide the specified elements for users without membership, but if an unregistered user visits the site, the elements are still displayed. Would it be possible to hide it for unregistered users as well?

Also, is it possible to do the hiding in the same way as other listing elements, i.e. by covering it with a button that, when clicked, opens a popup informing the user that they should purchase a membership? Currently, a user who is not allowed to view the elements would not know that these elements exist, but it would be nice for them to know since this might increase the likelihood of them purchasing a membership.

  1. Thank you for waiting. The code snippet was tested locally, and it hides the map and address for listings for unregistered users, too. Please disable third-party plugins and customizations (if there are any) and check if this issue persists. If you use a caching plugin, make sure that caching is disabled for logged-in users.

  2. Sorry, there’s no simple code snippet for this, it would require a custom implementation. If customizations beyond the available features are required for your site, please consider hiring someone for custom work

P.S. If you purchased a theme or extension, please enter the license key in the forum profile settings, this will enable the Premium Support badge and ensure a 24-hour turnaround time.

  1. No problem and thanks for getting back to me. I’ll try disabling third-party plugins and customizations and report back in case that should not have worked.

  2. I understand, thanks for clarifying.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.