Vendor Description in Listing Page

How can I edit this snippet so that it only displays on the item page only? Currently, it displays in other areas where the vendor block is.

add_filter(
	'hivepress/v1/templates/vendor_view_block/blocks',
	function( $blocks, $template ) {
		$vendor = $template->get_context('vendor');
		
		if($vendor && $vendor->get_description()){
			$blocks = hivepress()->helper->merge_trees(
					[ 'blocks' => $blocks ],
					[
						'blocks' => [
							'vendor_content' => [
								'blocks' => [
									'vendor_description' => [
										'type'   => 'content',
										'content'   => $vendor->display_description(),
										'_order' => 50,
									],
								],
							],
						],
				]
				)['blocks'];
		}
		
		return $blocks;
	},
	1000,
	2
);

Please try this PHP snippet instead

add_filter(
	'hivepress/v1/templates/vendor_view_block/blocks',
	function( $blocks, $template ) {
		
		// This condition was added.
		if('listing_view_page' !== hivepress()->router->get_current_route_name()){
			return $blocks;
		}
		
		$vendor = $template->get_context('vendor');
		
		if($vendor && $vendor->get_description()){
			$blocks = hivepress()->helper->merge_trees(
					[ 'blocks' => $blocks ],
					[
						'blocks' => [
							'vendor_content' => [
								'blocks' => [
									'vendor_description' => [
										'type'   => 'content',
										'content'   => $vendor->display_description(),
										'_order' => 50,
									],
								],
							],
						],
				]
				)['blocks'];
		}
		
		return $blocks;
	},
	1000,
	2
);
1 Like

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