Adding vendor links to the listing block footer

How do we make this customization happen when I want to change messaging buttons on the first page to vendor links, so customers can find their service providers quickly on the marketplace of my website quickly? Thanks, Hivepress team.

Please try this PHP snippet

add_filter(
	'hivepress/v1/templates/listing_view_block/blocks',
	function ($blocks, $template){
		$listing = $template->get_context('listing');
		
		if(!$listing){
			return $blocks;
		}
		
		$vendor_id = $listing->get_vendor__id();
		
		if(!$vendor_id){
			return $blocks;
		}
		
		return hivepress()->helper->merge_trees(
					[ 'blocks' => $blocks ],
					[
						'blocks' => [
							'listing_actions_primary' => [
								'blocks' => [
									'listing_vendor_link' => [
										'type'   => 'content',
										'content'  => '<a href="'.esc_url( hivepress()->router->get_url( 'vendor_view_page', [ 'vendor_id' => $vendor_id ] ) ).'">View vendor</a>',
										'_order' => 30,
									],
								],
							],
						],
				]
				)['blocks'];
	},
	1000,
	2
);
3 Likes

Some listings are not published via vendors but in blocks it’s showing “View Vendor” for all listing and when visitors click on it, page is redirected to Home Page.

Please add some codes to hide this text “View Vendor” when listing is not published from vendor

Please make sure that the vendor profile is published in WordPress/Vendors, then a link should work - the snippet above checks if a vendor profile exists first.

How to show vendor profile photo instead of “View vendor” text

1 Like

Yes I would like to know as well. That looks nice with photos on bottom.

Sorry, there’s no simple code for this, this would require embedding custom template parts like in TaskHive theme. If you’re familiar with customizations please check this tutorial Customizing Templates I HivePress Developer Docs - YouTube

I was having the same problem, and got it working. It shows the original link from the code above, but will also show the vendor name instead of the text “View vendor”. Hope this helps anyone.

add_filter(
	'hivepress/v1/templates/listing_view_block/blocks',
	function ($blocks, $template){
		$listing = $template->get_context('listing');
		
		if(!$listing){
			return $blocks;
		}
		
		$vendor_id = $listing->get_vendor__id();
		
		if(!$vendor_id){
			return $blocks;
		}
		
		return hivepress()->helper->merge_trees(
					[ 'blocks' => $blocks ],
					[
						'blocks' => [
							'listing_actions_primary' => [
								'blocks' => [
									'listing_vendor_link' => [
										'type'   => 'content',
										'content'  => '<a href="'.esc_url( hivepress()->router->get_url( 'vendor_view_page', [ 'vendor_id' => $vendor_id ] ) ).'"><p><strong>'.esc_html($listing->get_vendor__name()).'</strong></p></a>',
										'_order' => 30,
									],
								],
							],
						],
				]
				)['blocks'];
	},
	1000,
	2
);

4 Likes

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