Add minimum and maximum booking duration to secondary display area

When the minimum booking duration is set, for instance a week, and someone tries to rent for less period of time, it automatically jumps to the date that corresponds the chosen minimum period. The problem is that it looks like a bug and it’s not obvious why it is happening. There is no notice explaining as to why the user cannot choose the specific date. Is there any way to display the notice about why that date cannot be selected?

Hi,

Thank you for your feedback, we will definitely improve the UI\UX. Also, please check out this topic Display booking settings in the secondary attributes area - #6 by andrii

Thank you, Andrii. Is there a way to show minimum and the maximum booking durations on page (secondary or primary)?

Hi,

This is possible but will require additional customization. Please use this PHP snippet as an example:

add_filter(
	'hivepress/v1/templates/listing_view_page/blocks',
	function( $blocks, $template ) {
		$listing = $template->get_context('listing');
		
		if(!$listing || !hivepress()->get_version('bookings') || hivepress()->booking->is_time_enabled($listing)){
			return $blocks;
		}
		
		$booking_min = intval($listing->get_booking_min_length());
		$booking_max = intval($listing->get_booking_max_length());
		
		if(!$booking_min || !$booking_max || $booking_min > $booking_max){
			return $blocks;
		}
		
		return hivepress()->helper->merge_trees(
					[ 'blocks' => $blocks ],
					[
						'blocks' => [
							'page_sidebar' => [
								'blocks' => [
									'custom_booking_time' => [
										'type'   => 'content',
										'content'  => '<p>Booking duration min: '.($booking_min).'</p><p>Booking duration max: '.($booking_max).'</p>',
										'_order' => 11,
									],
								],
							],
						],
				]
				)['blocks'];
	},
	1000,
	2
);

Thank you, Andrii, but I was not able to successfully use this code. Can you let me know what I should change in the code to have it properly work? It does not seem to have any effect.

Hi,

It displays the minimum and maximum booking duration on the Page (primary), as shown in the screenshot Chalet espectacular en Albacete – RentalHive.png - Google Drive

I have a custom template for listing page. I have attribute primary and secondary displayed on the template, but the information on minimum and maximum booking periods does not show up. Which element should I use in the template?

Hi,

Please use this PHP snippet:

add_filter(
	'hivepress/v1/models/listing/attributes',
	function( $attributes ) {
		if ( isset($attributes['booking_min_length']) ) {
			$attributes['booking_min_length']['display_areas'] = ['view_page_secondary'];
			$attributes['booking_min_length']['display_format'] = '%label%: %value%';
		}
		
		if ( isset($attributes['booking_max_length']) ) {
			$attributes['booking_max_length']['display_areas'] = ['view_page_secondary'];
			$attributes['booking_max_length']['display_format'] = '%label%: %value%';
		}

		return $attributes;
	},
	1000
);
1 Like

Hi there Team HP (Andrii)

Just today I asked Ihor in a followup to some custom development that was done for us, how to add attributes to the hp-listing__attributes–secondary block in the hp-listing–view-page and here we have the answer. GREAT!

What would the code line be to set the order in which the attributes are displayed in the block?

We also have Allow sellers to add price extras have enabled and used

if ( isset($attributes['price_extras']) ) {
			$attributes['price_extras']['display_areas'] = ['view_page_secondary'];
			$attributes['price_extras']['display_format'] = '%label%: %value%';
		}

to add the attribute to the block, howeevr if there are no extras added in the listing the isset doesn’t seem to be working as in the listing page view it is displaying as Extras: %value% .

THANKS in advance. :upside_down_face:

Hi,

If you mean to show even if there is no value, then unfortunately, there is no such option. But if you are referring to the order of the attributes, you can do this through the _order parameter Search · user:hivepress change order · GitHub

Hi there Andrii.

So I did some thinking and your snippet above is to add the attributes to the block. I thought I can the attribute’s order in the block with the same snippet, but obviously not.

The Github link you supplied changes the order of the secondary attribute block on the listing view page. I need to change the order of the attributes inside the block.

Some of the attributes are system attributes (price_extras - OPTIONAL EXTRA, booking_offset - PURCHASE OFFSET) and some have been created as system attributes in custom development by Ihor (munchies4u_booking_days - DAYS AVAILABLE, munchies4u_booking_cut_off - PURCHASE BEFORE, munchies4u_bundle_size - H&E BUNDLE SIZE, munchies4u_menu_options - H%E MENU OPTIONS). So they are not custom attributes that I created Listings>Attributes (starches - STARCHES, vegetable - VEGETABLES, collection_from - COLLECT AFTER, collection_to - COLLECT BEFORE) and can set their order in the Listings>Attributes when created.
So I’m looking for a snippet to change the order of the system and the developed attributes by Ihor inside the attributes_secondary block and to hide them (price_extras) when no values have been set.

I’ve search through the GitHub repository and can not find any snippet that sets the order of the attributes in the block.

Thank you Andrii. It works now. I’ve added days after the value, but if the value is 1, I want to display 1 day instead of 1 days. is there a simple way to do that? Thank you, once again.

Hi,

Sorry, there’s no simple code snippet for this, it would require a custom implementation.

Is there a way to set the minimum and maximum booking duration as 2?

Hi,

You can use the sample snippet from this topic Maximum duration of the reservation (days).

Please note that it can require further customization.

I used the following snippet:

add_action('hivepress/v1/models/listing/create', function($listing_id) {
	update_post_meta($listing_id, 'hp_booking_min_length', 2);
})

It does not seem to be doing anything.

Hi,

Sorry for the inconvenience. We just provided a sample code that you can use. For it to work, you need to modify it, dependencies to the field, etc. Please note that we cannot help customize your website as a part of the fixed-price theme license; it includes fixing bugs and guidance about the available features Support Policy | HivePress.

If customizations are required for your site, please try customizing it using the collection of code snippets Search · user:hivepress · GitHub and other developer resources, or consider hiring someone for custom work https://fvrr.co/32e7LvY

​I hope this is helpful to you.

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