Hide "Add a listing" Button only to specific Plan

Hi there,

I would like to hide the “Add a listing” button only to users that have selected a specific plan (membership). All my users have to select a plan prior to use the site. Then regular users (buyers) have Membership1. I have two types of vendors with Plans: Membership2 and Membership3

I would like to hide the button “Add a listing” to buyers with Membership1, but show it to vendors with Membership2 and Membership3. is that possible?

Thanks,

1 Like

Please try this PHP snippet. Please just change your_membership_plan_id with the id of Membership1 plan

add_filter(
    'hivepress/v1/templates/site_header_block',
    function( $template ) {

    if(is_user_logged_in() && 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',
					],
				],
			]
		);
        }
    }

    return $template;
    },
    1000
);
1 Like

Hi yevhen,

Thanks fo the snippet. it works partially. The button is hidden when regular user with buyer Membership1 is logged in, and it shows to vendors once they have logged in. Thats is good!

However, it is also displayed when not one is logged in, so it is kind of displayed all the time by default. I would like to hide the button all the time, and to users that logged in with Membership1.
Then, only show the button to vendors that have logged in with membership2/3.

Can you please help me with this?

Thanks,

Please try this PHP snippet instead

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
);
2 Likes

Yevhen,

It works! Excellent, this help me a lot.

Thank you :slight_smile:

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