My listing owners have the ability to upload their own booking terms for their listing in pdf format. When clients book their property the client should accept the terms. For that I just added a checkbox that they confirm, but I need an URL to that listing attachment. Not sure what is the best approach. I was thinking to use the %listing.attachment% object in URL format but it does not work. Just prints the text. The URL would be unique for every listing.
Thanks for the answer Andrii and the suggested workaround.
I’m familiar with PHP for other projects but still learning on the Wordpress specifics. I like they way everything can be customised as well and the coding practises for Hivepress. Also happy to hire someone at Fiverr at a later stage if required for certain functions if I would not have time.
One question to understand it better and have a lead where to start to customise.
“If I like to refer to an attribute of a listing anywhere from the project/page, how would that look like?”
I assume this would need to have the current “post ID” to “lookup” the attribute.
Please change put_your_checkbox_attribute_field_name on your booking checkbox attribute field name and please change get_put_your_url_attribute_field_name on get_ + listing URL attribute field name
That’s something I’m looking for, however does not work yet. I was trying to directly refer to the attachment attribute URL for the custom post type. It looks like HP is saving a field ID for the attachment as listing attachments are saved in the media gallery. I was onto this, which does not return anything until you shared the filter which would be better.
You filter does not generate the correct URL as the attribute is of the Field Type Attachment, not an URL type. Not sure how to fetch the URL.
Here is the listing attribute. To be clear, every listing will have an PDF uploaded which I like to lookup to URL from. Something like $listing->attachment_attribute->URL.
I further investigated to pull the data and by combining the wp_get_attachment_url() with the listing attachment attribute field value to lookup the URL. See the solution below in the filter.
Would you agree this is a solid solution?
add_filter(
'hivepress/v1/forms/booking_confirm',
function($form_args, $form){
$booking = $form->get_model();
if(!$booking){
return $form_args;
}
$listing = $booking->get_listing();
if(!$listing || !$listing->get_put_your_url_attribute_field_name()){
return $form_args;
}
$field_name = 'hp_algemene_voorwaarden'; // replace my_custom_field with the name of your custom field
$attachment_post_id = $listing->get_algemene_voorwaarden();
$attachment_url = wp_get_attachment_url( $attachment_post_id );
echo $attachment_url;
if(isset($form_args['fields']['algemene_voorwaarden'])){
$form_args['fields']['algemene_voorwaarden']['description'] = '<a href="'.esc_url($attachment_url).'" target="_blank" rel="noopener">Custom text</a>';
}
return $form_args;
},
1000,
2