Adding button "Send a message" on the Request page

Hi, I would like to add a button “Send a message” on the request page. There is currently “Send an offer” but nothing to send a message first to get information before making an offer.

I have found similar tickets :

Thank you for waiting. Please try this PHP code snippet to start but please note that it can require further advanced customization

add_filter(
	'hivepress/v1/templates/request_view_page/blocks',
	function ( $blocks, $template ) {
		if(hivepress()->get_version( 'messages' )){
			$request = $template->get_context('request');
			
			if(!$request){
				return $blocks;
			}
			
			$user = $request->get_user();
			
			if(!$user){
				return $blocks;
			}
			
			$vendor = \HivePress\Models\Vendor::query()->filter(['user' => $user->get_id()])->get_first();
			
			if(!$vendor){
				return $blocks;
			}
			
			$template->set_context('vendor', $vendor);
			
			return hivepress()->template->merge_blocks(
			$blocks,
			[
				'request_actions_primary' => [
					'blocks' => [
							'message_send_modal' => [
								'type'        => 'modal',
								'model'       => 'vendor',
								'title'       => hivepress()->translator->get_string( 'send_message' ),
								'_capability' => 'read',
								'_order'      => 5,

								'blocks'      => [
									'message_send_form' => [
										'type'       => 'message_send_form',
										'_order'     => 10,

										'attributes' => [
											'class' => [ 'hp-form--narrow' ],
										],
									],
								],
							],

							'message_send_link'  => [
								'type'   => 'part',
								'path'   => 'vendor/view/page/message-send-link',
								'_order' => 10,
							],
						],
				],
			]
		);	
		}
		
		return $blocks;
	},
	1000,
	2
);

Hi Yevhen, thank you for the snippet.
I have added it. The button Send a message now is displayed and works but only when the request is made by a vendor.
All users who only have a basic user account don’t have a Send a message button on their requests.

Do you know how to fix this ?
Thanks

Thank you for waiting. Unfortunately, there’s no simple code snippet for this. It would require an advanced custom implementation.

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