Category Name should be displayed on each of the Vendor's card Information

Hello everyone, I am using ExpertHive theme By Hivepress. Is it possible to display each Vendor’s category after their name on each of the vendor’s card information? I have attached the screenshot also for better understanding. Thanks!

Screenshot: Screenshot by Lightshot

Please try this PHP snippet but please note that it can require further customization. Unfortunately, in the current version, it is not possible to add links for vendor categories as it works for listing categories

add_filter(
	'hivepress/v1/templates/vendor_view_block/blocks',
	function( $blocks, $template ) {
		$vendor = $template->get_context('vendor');
		
		if(!$vendor || !$vendor->get_categories()){
			return $blocks;
		}
		
		$output = '<p>';
		
		foreach($vendor->get_categories() as $category){
			$output .= '<span>'.esc_html( $category->get_name() ).'</span>';
		}
		
		$output .= '</p>';
		
		return hivepress()->helper->merge_trees(
					[ 'blocks' => $blocks ],
					[
						'blocks' => [
							'vendor_content' => [
								'blocks' => [
									'custom_vendor_categories' => [
										'type' => 'content',
										'content' => $output,
										'_order' => 11,
									],
								],
							],
						],
				]
				)['blocks'];
	},
	1000, 
	2
);

Thank you so much. It’s working. Now I am asking a little question to you about this Vendor Registration. Imagine a vendor has two categories. So both the two categories are showing but there is no gap and comma"," between this category. Please check the attached screen shot for better understanding. Can you please just edit this code snippet a little so that it would be work perfectly. Thanks.

Screenshot: Screenshot by Lightshot

Please try this PHP snippet instead

add_filter(
	'hivepress/v1/templates/vendor_view_block/blocks',
	function( $blocks, $template ) {
		$vendor = $template->get_context('vendor');
		
		if(!$vendor || !$vendor->get_categories()){
			return $blocks;
		}
		
		$output = '<p>';
		
		foreach($vendor->get_categories() as $category){
			if(strpos($output, '<span>') !== false){
				$output .= '<span>, '.esc_html( $category->get_name() ).'</span>';
			}else{
				$output .= '<span>'.esc_html( $category->get_name() ).'</span>';	
			}
		}
		
		$output .= '</p>';
		
		return hivepress()->helper->merge_trees(
					[ 'blocks' => $blocks ],
					[
						'blocks' => [
							'vendor_content' => [
								'blocks' => [
									'custom_vendor_categories' => [
										'type' => 'content',
										'content' => $output,
										'_order' => 11,
									],
								],
							],
						],
				]
				)['blocks'];
	},
	1000, 
	2
);
1 Like

Thanks a lot again! Can you help to solve another issue please?

In the Services page there is a Category search option on the top but In the Professionals / Experts page there is no category search option on the top. Is it possible to make the Experts page search same as like the services page search?

I have attached the screenshot for your better understanding. Thanks!

Please try this PHP snippet. Then please choose the Categories option in HivePress/Settings/Vendors/Search/Default fields setting

add_filter(
	'hivepress/v1/settings',
	function ($config){
		$config['vendors']['sections']['search']['fields']['vendor_search_fields']['options']['category'] = 'Categories';
		
		return $config;
	},
	1000
);

add_filter(
	'hivepress/v1/forms/vendor_search',
	function ($form){
		$form['fields']['_category'] = array_merge(
			$form['fields']['_category'],
			[
				'type' => 'select',
				'placeholder'  => 'All Categories',
				'options'      => 'terms',
				'option_args'  => [ 'taxonomy' => 'hp_vendor_category' ],
				'_order'       => 20,
			]
		);
		
		if(!isset($form['fields']['_category']['display_type'])){
			$form['fields']['_category']['display_type'] = 'hidden';
		}
		
		return $form;
	},
	1000
);
1 Like