Show "Add Listing" button ONLY when vendor logged in

I need the Add Listing button in the top menu to only show when an ALREADY registered vendor is logged in. I found the snippet below, and it does remove the button until a user logs in, however it does not distinguish between a standard user and a vendor. Can you please help me modify it to only show the button when the logged in user is already a vendor?
I have a dedicated page where vendors can register the first time and add their first listing, with a link to “/submit-listing”.
So my flow would be, first a vendor would visit the vendors’ dedicated page, become a vendor and then the next time they login they will start seeing the “Add Listing” button in the header.
Standard (non-vendor) logged in users will not see the “Add Listing” button.

> add_filter(
>     'hivepress/v1/templates/site_header_block',
>     function( $template ) {
> 		
> 		if(is_user_logged_in()){
> 			if(hivepress()->get_version('memberships')){
> 				$membership = \HivePress\Models\Membership::query()->filter(['user' => get_current_user_id()])->get_first();
> 
>         		if(!$membership || your_membership_plan_id === $membership->get_plan__id()){
>             		$template = hivepress()->helper->merge_trees(
> 						$template,
> 						[
> 							'blocks' => [
> 								'listing_submit_link' => [
> 									'type' => 'content',
> 								],
> 							],
> 						]
> 					);
>         		}
>     		}
> 		}else{
> 			$template = hivepress()->helper->merge_trees(
> 				$template,
> 				[
> 					'blocks' => [
> 						'listing_submit_link' => [
> 							'type' => 'content',
> 						],
> 					],
> 				]
> 			);
> 		}
> 
>     return $template;
>     },
>     1000
> );

Hi, i used this php snippet to hide the listing button from regular users, hopefully it works for you.

add_filter(
	'option_hp_listing_enable_submission',
	function( $value ) {
		if ( ! is_admin() && ! current_user_can( 'edit_posts' ) ) {
			return false;
		}

		return $value;
	}
);
1 Like

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