Combining minimum and maximum guest count attribute on listing card

I’ve added a PHP snippet to show “minimum & maximum guest quantity” on the listing card (shown below for max. guest count), but I was hoping there was a way to customize it to combine both attributes and show: “Guests: [min#]-[max#]”

My website for reference.

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

		return $attributes;
	},
	1000
);

Unfortunately, there is no easy way to do it. It requires advanced customization. But as another solution, it is possible to use this PHP snippet. But please note that it can require further customization. If you are not familiar with the code customization, then please consider hiring someone for custom work https://fvrr.co/32e7LvY

add_filter(
	'hivepress/v1/templates/listing_view_block/blocks',
	function($blocks, $template){
		$listing = $template->get_context('listing');
		
		if(!$listing || !$listing->get_booking_min_quantity() || !$listing->get_booking_max_quantity()){
			return $blocks;
		}
		
		return hivepress()->template->merge_blocks(
			$blocks,
			[
				'listing_content' => [
					'blocks' => [
						'custom_listing_min_max_guest' => [
							'type' => 'content',
							'content' => '<strong>Guests: </strong>'.$listing->get_booking_min_quantity().' - '.$listing->get_booking_max_quantity(),
							'_order' => 40,
						]
					]
				]
			]
		);
	},
	1000,
	2
);

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