Hi there,
I want to display a custom link on the booking page, how can I do that?
Idea is to add a link to additional documents in Google Drive here. Is there a snippet I can use?
Hi there,
I want to display a custom link on the booking page, how can I do that?
Idea is to add a link to additional documents in Google Drive here. Is there a snippet I can use?
Hi,
You can add it by using bookings attributes: How to add booking attributes - HivePress Help Center.
Great, thanks. How can I make that a variable value that depends on the vendor? I guess there is a snippet for that?
If you insert a custom template part or just HTML code to the hivepress/v1/templtes/booking_view_page
template, then it should have the $booking object available, and you can get vendor this way:
$vendor=$booking->get_listing__vendor();
This way you can fetch vendor details, or add conditions based on vendor fields, e.g.:
$vendor->get_name();
Hope this helps
P.S. Please consider hiring a freelance developer for implementing this Experts | HivePress because the feature (uploading files via Google Drive API and then sharing them automatically) is pretty complex. While we can help with some guidance, unfortunately, we can’t provide ready-made code snippets regarding this or debug third-party custom code because this is beyond the theme support scope (it includes fixing bugs in the existing features and guidance about the existing features).
Thanks Ihor, that seems like a good approach. Are you sure the $booking object is available? As it seems I get an error everytime I try to get data from it.
add_filter(
'hivepress/v1/templates/booking_view_page',
function ($args) {
$listing = $booking->get_listing();
$vendor=$listing->get_vendor();
$vendor_id = $listing->get_user__id();
if(!$vendor_id){
return;
}
return hivepress()->template->merge_blocks(
$args,
[
'page_content' => [
'blocks' => [
'booking_details_primary' => [
'blocks' => [
'new_element' => [
'label' => 'Archivos',
'type' => 'content',
'content' => '<div>Custom text</div>',
'attributes' => [
'id' => 'booking_details_primary',
],
],
],
],
],
]
]
);
},
1000
);
Please try using the hivepress/v1/templates/booking_view_page/blocks
hook instead Filter: hivepress/v1/templates/{template_name}/blocks | HivePress Hook Reference then the first function argument is $blocks
(so you can add new blocks or change the existing ones and return $blocks
at the end of the function), and the second one is $template
, this way you get context variables from the template, for example:
$booking=$template->get_context('booking');
Thanks Ihor, that worked. Below my code for anybody wanting to do something similar:
add_filter(
'hivepress/v1/templates/booking_view_page/blocks',
function($blocks, $template){
$booking = $template->get_context('booking');
if(!$booking){
return $blocks;
}
$listing = $booking->get_listing();
if(!$listing){
return $blocks;
}
$vendor = $listing->get_vendor();
if(!$vendor){
return $blocks;
}
$vendor_id = $listing->get_user__id();
$user = $listing->get_user();
$vendor_name = $user->get_display_name();
$template->set_context('vendor', $vendor);
return hivepress()->template->merge_blocks(
$blocks,
[
'new_element' => [
'label' => 'Archivos',
'type' => 'content',
'content' => '<div><a href="http://yoursl.andreasl27.sg-host.com/'. $vendor_id.'" target=”_blank”"><button type="submit" class="hp-form__button button-primary alt button hp-field hp-field--submit" data-component="button" data-icon="arrow-right"><span>Archivos de '.$vendor_name.'</span></button></a></div>',
'_order' => 30,
],
],
);
},
1000,
2
);
I managed to use YOURSL as a custom URL for the file folders.