Only display the Marketplace Dashboard if vendor has listings in certain categories?

Hi,

I’m building a platform that’s a combination of a directory and a marketplace. In some categories the vendors don’t sell anything, they simply list the information, so there is no need for a dashboard that tells them their “revenue.”

In other categories, they can sell things. That’s when the dashboard is necessary.

Is there a way to separate the two types of vendors and only display the dashboard on vendors who has listings in the categories that sell things?

Thanks

Please try this PHP snippet. Please just change 1,2,3 on listing categories which vendor should have to see the vendor dashboard

add_filter(
	'hivepress/v1/menus/user_account/items',
	function($menu){
		
		if(!current_user_can('edit_posts')){
			return $menu;
		}
		
		$vendor_id = HivePress\Models\Vendor::query()->filter(['user' => get_current_user_id()])->get_first_id();
		
		if(!$vendor_id){
			return $menu;
		}
		
		$listing = HivePress\Models\Listing::query()->filter(['vendor' => $vendor_id, 'categories__in' => [1,2,3]])->get_first_id();
		
		if($listing){
			return $menu;
		}
		
		unset($menu['vendor_dashboard']);
		
		return $menu;
	},
	1000
);
1 Like

Wow! This is perfect. Thank you!

1 Like