Make social link reveal with a membership offer

Hello,

Is it possible to make social link only visible for people who subscribe to a membership ? Like it is possible currently for vendor attribute :

Thanks in advance.

Sorry, there’s no such feature at the moment but we’ll consider adding it. There can be a temporary code snippet for hiding these links completely for non-members, let me know if this works for you.

Thank you. If anyone here could help me with the corresponding snippet it could be great !

Thanks in advance.

Please try this PHP snippet. It will hide social links on the vendor page when a user does not has any membership plan

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

        		if(!$membership){
 					$template = hivepress()->helper->merge_trees(
						$template,
						[
							'blocks' => [
								'vendor_social_links' => [
									'type' => 'content',
								],
							],
						]
					);
        		}
			}
		}

    	return $template;
	},
	1000
);

Hello,

The snippet seems to work however, social media button are totally disapearing when the user has no membership plan. Do you have any clue to make it looking like the number, a disclosable button :

Thanks in advance for your help.

Zak.

Unfortunately, there is no simple snippet for making it like a disclosable button. It requires advanced customization. But please try this snippet as a workaround. It will add text that social links are hidden if user does not have any active membership plan

add_filter(
		'hivepress/v1/templates/vendor_view_page',
		function( $template ) {
	
		if(hivepress()->get_version('memberships')){
			if(!is_user_logged_in()){
				$template = hivepress()->helper->merge_trees(
					$template,
					[
						'blocks' => [
							'vendor_social_links' => [
								'type' => 'content',
								'content' => '<p>Please activate membership plan to view social links</p>',
								'_order' => 25,
							],
						],
					]
				);
			}else{
				$membership = \HivePress\Models\Membership::query()->filter(['user' => get_current_user_id()])->get_first();

        		if(!$membership){
 					$template = hivepress()->helper->merge_trees(
						$template,
						[
							'blocks' => [
								'vendor_social_links' => [
									'type' => 'content',
									'content' => '<p>Please activate membership plan to view social links</p>',
									'_order' => 25,
								],
							],
						]
					);
        		}
			}
		}

    	return $template;
	},
	1000
);
1 Like

Thank you it will be cool for the moment.

In the future update it could be cool to be able to manage the social links with the membership like every other vendor attribute.

I’ll make this proposal in the dedicated section. Edit : It’s already there.

Thanks, Zak.

There is one breach with the snippet. I have an offer which allows only to reveal one phone number. However if the user buy this offer and don’t spent his “credit”, he will be able to see all the social links whithout paying.

This is why it could be great to have social links managable in membership plans.

Please try this PHP snippet

add_filter(
		'hivepress/v1/templates/vendor_view_page/blocks',
		function( $blocks, $template ) {
		$vendor = $template->get_context('vendor');
		$reveal_ids = hivepress()->request->get_context( 'membership_reveal_ids' );
		
		if(!$vendor){
			return $blocks;
		}
			
		
		if(hivepress()->get_version('memberships')){
			if(!is_user_logged_in()){
				$blocks = hivepress()->helper->merge_trees(
					[ 'blocks' => $blocks ],
					[
						'blocks' => [
							'vendor_social_links' => [
								'type' => 'content',
								'content' => '<a href="#membership_reveal_modal_'.$vendor->get_id().'" class="hp-link"><i class="hp-icon fas fa-eye"></i><span>Reveal social links</span></a>',
								'_order' => 25,
							],
						],
				]
				)['blocks'];
			}else{
				$membership = \HivePress\Models\Membership::query()->filter(['user' => get_current_user_id()])->get_first();

        		if(!$membership || !in_array($vendor->get_id(), $reveal_ids)){
 					$blocks = hivepress()->helper->merge_trees(
					[ 'blocks' => $blocks ],
					[
						'blocks' => [
							'vendor_social_links' => [
								'type' => 'content',
								'content' => '<a href="#membership_reveal_modal_'.$vendor->get_id().'" class="hp-link"><i class="hp-icon fas fa-eye"></i><span>Reveal social links</span></a>',
								'_order' => 25,
							],
						],
				]
				)['blocks'];
        		}
			}
		}

    	return $blocks;
	},
	1000,
	2
);

Hello,

I tried the snippet.

First of all, there is one issue with this snippet. When the user buy one credit, he will be able to reveal one vendor phone number and social media at the same time. However, they are not disclose when the credit is consumed and the user need to buy a second time the plan to be able to see the revealed number and social links.

Secondly, I was more thinking about this king of restrictions :

When a user take the first plan he will be able to reveal only one phone number and only phone numbers.

When a user take the second plan all the phone number and social link will be revealed to him.

There is two way to make it possible :

Weither we can restrict the access to all vendor individual pages to user with the second plan (because social link are only in vendors pages) or we can restricte the social link attribute (as you did in your snippet) but make it reveal only if the user take the second plan.

Here is what would be really perfect for the membership plan I’m trying to implement.

In the future updates, I suggest to make the social link plugin connected to the membership, to be able to control social links in our different plans. it would be great.

Thank you very much for all your great work btw.

Zak.

Thanks, we’ll consider adding social links as a separate per-plan restriction in future Memberships versions.

Unfortunately there’s no way to reveal social links separately in the current version, this is related to how the Memberships extension works - when you reveal something, you don’t reveal just this attribute, but you reveal the whole listing or vendor (depending on the revealed details). So if you reveal Phone then all other restricted attributes for this listing or vendor are also revealed.

The reveal count means the number of listings/vendors a user can reveal, not the number of separate attributes. If Phone is the only attribute you restrict then it’s basically the same since there’s 1 restricted attribute per listing.

With the snippet above if someone reveals a Phone, the social links are also revealed after the page refresh (the reveal count is reduced by 1 then, since 1 listing is revealed). Please consider setting up plans according to this functionality, if you offer a plan with 1 reveal count then this basically means users can reveal any listing or vendor of their choice, and buy another plan to reveal more.

Okay thanks, I understand better thanks to your explaination. Îm hoping to see the option coming soon :+1:

In term of design, in this configuration, it will be better juste to have a text (just like the first snippet you did) saying « Reveal phone number to reveal social links » so it will be clear for people.

Could you please just also do something for this issue :

Thanks, Zak.

Thanks, it indeed sounds like “reveal just this attribute”, we’ll try to improve the UX because the reveal action actually reveals the whole listing or vendor.
Please make sure that you have the latest Memberships version, we fixed this bug recently - the revealed listing/vendors should remain visible even if the reveal limit is exceeded.
For social links, please try this snippet instead:

add_filter(
	'hivepress/v1/templates/vendor_view_page/blocks',
	function( $blocks, $template ) {
		$vendor = $template->get_context( 'vendor' );

		if ( $vendor && ! in_array( $vendor->get_id(), hivepress()->request->get_context( 'membership_reveal_ids', [] ) ) ) {
			$blocks = hivepress()->helper->merge_trees(
				[ 'blocks' => $blocks ],
				[
					'blocks' => [
						'vendor_social_links' => [
							'type'    => 'content',
							'content' => '<a href="#membership_reveal_modal_' . $vendor->get_id() . '" class="hp-link"><i class="hp-icon fas fa-eye"></i><span>Reveal Social Links</span></a>',
							'_order'  => 25,
						],
					],
				]
			)['blocks'];
		}

		return $blocks;
	},
	1000,
	2
);

Yes the update corrected the problem but I think when I activate the snippet you provide me 2 days ago, it overwrite the update and make the problem come back again. I’ll try the new snippet and let you know.

Thanks !

EDIT : The snippet is working thank.

Just replace the content line by :

'content' => '<div style="text-align: center;">Please reveal the phone number to display the social networks.</div>'

It looks like that now :

Thanks for your time and help, Zak.

1 Like