Hi, im trying to add a select field with the current user’s bookings to the message form.
I coded some snippets and it works but I dont know if it is the best way to doit… If I try to use the same function for the filters: “hivepress/v1/models/message” and “hivepress/v1/forms/message_send” the items on the select get duplicated…
and after adding this code sometimes the attachments wont appear in the conversation, they get uploaded and the meta is inserted but they are not listed on the conversation…
If somebody can take a look at my code and tell me how to improve it/change it or if it is a better way to accomplish this…
// link messages to bookings
add_filter( 'hivepress/v1/models/message', 'custom_add_message_fields1', 1000 );
function custom_add_message_fields1($form){
$bookingsmsg = [];
$bookingsmsg = \HivePress\Models\Booking::query()->filter(
[
'status__in' => [ 'pending', 'publish' ],
'user' => get_current_user_id(),
]
)->get();
if ($bookingsmsg){
foreach($bookingsmsg as $respuesta) {
$msglisting = \HivePress\Models\Listing::query()->get_by_id( $respuesta->get_listing__id() );
$titulo = $msglisting->get_title();
$options[intval($respuesta->get_id())] = $titulo;
}
}
$form['fields']['msgbooking'] = [
'label' => 'Cita',
'type' => 'select',
'options' => $options,
'placeholder' => 'Selecionar cita',
'description' => '<span style="color: red;">Si tu mensaje esta relacionado a una cita, seleccionala aquí.<//span>',
'_external' => true,
'_order' => 3,
];
return $form;
}
add_filter( 'hivepress/v1/forms/message_send', 'custom_add_message_fields', 1001 );
function custom_add_message_fields($form){
$form['fields']['msgbooking'] = [
'label' => 'Cita',
'type' => 'select',
'_external' => true,
'_order' => 3,
];
return $form;
}
add_filter(
'hivepress/v1/models/message/attributes',
function($attributes){
$attributes['msgbooking'] = [
'editable' => true,
'edit_field' => [
'label' => 'Cita',
'type' => 'select',
'_external' => true,
'_order' => 3,
]
];
return $attributes;
},
1000
);
Thank you