Making the image when listing, required instead of optional

Hi,

How do you make the image, when listing a property, required instead of optional? so that there always is a picture on each listing.

I would also like to know how to select a maximum amount of days you can book a property, for example: (30-31 days for a monthly booking). so that this is pre-determined when someone lists their property, so that it is not optional as it is now.

Kind regards,

John Worsley

  1. Please try this PHP snippet Require uploading at least one image for listings #hivepress #listings · GitHub

  2. Please try to set 30-31 days in Booking Window attribute for listing. The booking window is the max number of days a booking can be made in advance, for example, if you set it to 30-31 then bookings can be made only 1 month in advance (so it is not possible to book something 10 years from now).

1 Like

Hi,

  1. Where exactly should I put in this PHP snippet you sent me?

  2. I also can’t seem to find how to set the booking window at 31 days so that it is un-changeable for the host (so that the host, that is putting up a listing, can’t manually put in more than 31 days). I also don’t think that booking window is what we are after (as we don’t want to hinder someone from making bookings in advance but instead want to make it impossible to book more than 31 days in a row). we want to do this so that we can set monthly booking prices so that users only can book 1 month maximum per “property”.

  3. How do you edit the attributes (like for example “opening hours” or “description” )
    when completing “list a property” . Some of them didn’t show up in the (listings)->(attributes) admin view on Wordpress.

Thank you in advance!

  1. Please try following these instructions How to add custom code snippets - HivePress Help Center

  2. If you want to restrict the max possible booking length to 31 days for any booking, you can try this PHP snippet:

add_filter(
	'hivepress/v1/forms/booking_confirm/errors',
	function( $errors, $form ) {
		$booking = $form->get_model();
		
		if($booking && ((intval($booking->get_end_time()) - intval($booking->get_start_time())) / DAY_IN_SECONDS) > 31){
			$errors[] = 'Please change dates because booking can not be more than 31 days';
		}
		
		
		return $errors;
	},
	1000,
	2
);
  1. Yes, these fields are added via extensions (unlike the custom attributes). It is possible to edit them, but via the code snippets, for example Make the listing description field optional #hivepress #listings · GitHub

Thank you, it worked :smile:

In addition to making it required, is it possible to make it mandatory for the user to add 3 images or more? How can I do that?

Please try this PHP snippet

add_filter(
	'hivepress/v1/forms/listing_update/errors',
	function( $errors, $form ) {
		$listing = $form->get_model();

		if ( $listing && count((array)$listing->get_images__id()) < 3 ) {
			$errors[] = 'Please upload at least 3 images.';
		}

		return $errors;
	},
	1000,
	2
);

Thanks! This worked. One question though, I now the “make images required” as well as “make at lease 3 images mandatory” php snippets active. Any possible issues that this may cause?

It is recommended to use one of them as they do the same things but with different conditions.

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