tomp
August 21, 2022, 1:04pm
1
Hello,
I am looking to set a default value and hide the following listing attributes so they can’t be edited by the user and won’t be shown to them when creating a listing.
BOOKING AVAILABLE FROM
BOOKING AVAILABLE TO
BOOKING SLOT DURATION
BOOKING SLOT INTERVAL
I would also like to have BOOKING REQUESTS always checked for “Manually accept new bookings” and hide that as well.
Thanks for all the help,
Tom
1 Like
yevhen
August 22, 2022, 10:50am
4
Please try this PHP snippet but please note that it can require further customization
add_action('hivepress/v1/models/listing/create', function($listing_id) {
if(hivepress()->get_version( 'bookings' )){
update_post_meta($listing_id, 'hp_booking_slot_duration', 10);
update_post_meta($listing_id, 'hp_booking_min_time', 0);
update_post_meta($listing_id, 'hp_booking_max_time', 0);
update_post_meta($listing_id, 'hp_booking_slot_interval', 10);
update_post_meta($listing_id, 'hp_booking_moderated', true);
}
});
add_filter(
'hivepress/v1/models/listing/attributes',
function( $attributes ) {
if ( isset($attributes['booking_slot_duration']) ) {
$attributes['booking_slot_duration']['editable'] = false;
}
if ( isset($attributes['booking_min_time']) ) {
$attributes['booking_min_time']['editable'] = false;
}
if ( isset($attributes['booking_max_time']) ) {
$attributes['booking_max_time']['editable'] = false;
}
if ( isset($attributes['booking_slot_interval']) ) {
$attributes['booking_slot_interval']['editable'] = false;
}
if ( isset($attributes['booking_moderated']) ) {
$attributes['booking_moderated']['editable'] = false;
}
return $attributes;
}
);
tomp
August 22, 2022, 12:28pm
5
The default values worked great thank you for that but the filter doesn’t seem to be hiding the attributes. I added the add_filter code to functions.php
tomp
August 22, 2022, 5:02pm
8
I found the issue with the filter! It was missing the ,1000 at the end of the filter
add_action('hivepress/v1/models/listing/create', function($listing_id) {
if(hivepress()->get_version( 'bookings' )){
update_post_meta($listing_id, 'hp_booking_slot_duration', 10);
update_post_meta($listing_id, 'hp_booking_min_time', 0);
update_post_meta($listing_id, 'hp_booking_max_time', 0);
update_post_meta($listing_id, 'hp_booking_slot_interval', 10);
update_post_meta($listing_id, 'hp_booking_moderated', true);
}
});
add_filter(
'hivepress/v1/models/listing/attributes',
function( $attributes ) {
if ( isset($attributes['booking_slot_duration']) ) {
$attributes['booking_slot_duration']['editable'] = false;
}
if ( isset($attributes['booking_min_time']) ) {
$attributes['booking_min_time']['editable'] = false;
}
if ( isset($attributes['booking_max_time']) ) {
$attributes['booking_max_time']['editable'] = false;
}
if ( isset($attributes['booking_slot_interval']) ) {
$attributes['booking_slot_interval']['editable'] = false;
}
if ( isset($attributes['booking_moderated']) ) {
$attributes['booking_moderated']['editable'] = false;
}
return $attributes;
},
1000
);
Thank you for all the help,
Tom
2 Likes
system
Closed
September 21, 2022, 5:03pm
9
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.