Make "Manually Accept new booking" - Required

Hi HivePress Team,

I would like to make “Manually Accept new booking” Mandatory, and indicate user that this option needs to be checked when submitting a new listing or updating one.

Could you please help me with snippet for this?

i searched the snippets but I could not find one for this.

Thanks,

Please try this PHP snippet

add_filter(
	'hivepress/v1/models/booking/attributes',
	function( $attributes ) {
		if ( isset($attributes['booking_moderated']) ) {
			$attributes['booking_moderated'] = [
				'edit_field'     => [
					'required' => true,
				],
			];
		}

		return $attributes;
	}
);

Hi yevhen,

I tested this snippet but it does not work. I unchecked the “Accept Booking Manually”, but It allows me to add a new listing or modify an existing listing

My goal is that the option “Accept Booking Manually” should be always checked when creating or modifyng a listing. if customer does not check it, then it shows a message indicating to the customer to check that option.

Thanks,

Sorry for inconvience. Please try this PHP snippet instead

add_filter(
	'hivepress/v1/forms/listing_update',
	function( $form ) {
		if ( isset( $form['fields']['booking_moderated'] ) ) {
			$form['fields']['booking_moderated']['required'] = true;
		}

		return $form;
	},
	1000
);

Hi yevhen,

Thanks. this last snippet partially works. It makes the “Accept Manually Booking” mandatory.
The form is not sent unless I checked this option. But this is what happens

  • Option is not checked
  • Click the “Submit Listing” button. Nothing happens.
  • The button does not send form, But > there is not error message indicating that the issue is that the field “Accept Manual booking” needs to be checked
  • It is a confusing, because user does not know the reason the submit button does not work.

I am not sure if it is possible to create something like the snippet for In this snippet there is an error message : “Please upload the profile image” as an indication that image is required.

I hope this is possible to do, if not I keep the last snippet.

Thanks,

Please try this PHP snippet instead

add_filter( 
	'hivepress/v1/forms/listing_update/errors', 
	function ( $errors, $form ) {
		if(hivepress()->get_version( 'bookings' ) && !$form->get_value('booking_moderated')){
			$errors[] = 'Please allow manually accepting new bookings ';
		}
		
		return $errors;
	},
	1000,
	2
);

add_filter(
	'hivepress/v1/forms/listing_update',
	function( $form ) {
		if ( isset( $form['fields']['booking_moderated'] ) ) {
			$form['fields']['booking_moderated']['required'] = true;
		}

		return $form;
	},
	1000
);
1 Like

Awesome. This snippet works!!! :slight_smile:

Thanks!

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