How can I set a default value for a listing attribute and hide it from listing creation

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.

image

Thanks for all the help,
Tom

1 Like

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;
	}
);

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

I found the issue with the filter! It was missing the ,1000 at the end of the filter

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

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