Price Calculation for Adults and Child / Number of Participants

Hi.
We are using the listing Hive Theme. All is now nicely working with the booking request and Calculation.
But, can I also add a price per Adult and per Child and can I enable it that the user is able to choose the number of person?

If yes, how would this work?

Hi, if you mean two separate prices, like one for an adult and a different price per child, then I do not think you can do that. I think you can only have one set price per listing. But you can add extra to the price by checking it in the hivepress/settings/listing/selling section (Allow sellers to add price extras). You can also make this price mandatory by checking a box as well. If not it will be optionable, as an add on price for the user.

Also, you can go to hivepress/settings/booking/places . Places Allow multiple places per booking. Places means like people. So when you go to extra section in the edit listing, you can charge extra price per amount of people.

Hope this helps, but note that I’m just new to this as well, building my site.

1 Like

Hi,

Unfortunately there’s no such feature yet, but we’ll consider adding it. Currently it’s possible to set the base price, and price extras (if these are enabled in settings).

Guys, this is a great workaround. I have tested it and it works.

One last question to the extras. Am I able to hide some of the options the the Vendor can use:
Per place per day etc. , so the he/she only has one option how the extra price calculates?

Yes you can hide the options. Use this code snippet to hide all the other 3 options and only allow the per day (or hour).

Add this in the code snippet plugin:

add_filter(
	'hivepress/v1/models/listing/attributes',
	function($attributes){
		if(isset($attributes['price_extras'])){
			$attributes['price_extras']['edit_field']['fields']['type']['options'] = [
				'' => 'per day',
			];
		}
		
		return $attributes;
	},
	1000
);

add_filter( 'hivepress/v1/models/listing/fields', 'change_price_extras_custom', 200, 2 );
add_filter( 'hivepress/v1/forms/listing_update', 'change_price_extras_custom', 200, 2 );
add_filter( 'hivepress/v1/meta_boxes/listing_attributes', 'change_price_extras_custom', 200 );
add_filter( 'hivepress/v1/models/vendor/fields', 'change_price_extras_custom', 200, 2 );
add_filter( 'hivepress/v1/forms/vendor_update', 'change_price_extras_custom', 200, 2 );
add_filter( 'hivepress/v1/meta_boxes/vendor_attributes', 'change_price_extras_custom', 200 );

function change_price_extras_custom($form, $model = null){
		$is_form    = strpos( current_filter(), 'form' );
		$is_model   = strpos( current_filter(), 'model' );
		$is_listing = strpos( current_filter(), 'listing' );
		$per_vendor = get_option( 'hp_booking_per_vendor' );

		if ( ! $is_listing && ! $per_vendor ) {
			return $form;
		}
		$fields = [];

		if ( $is_model ) {
			$fields = $form;
		} else {
			$fields = $form['fields'];
		}
		$listing_id = null;

		if ( $is_listing ) {
			if ( $is_model ) {
				$listing_id = $model->get_id();
			} elseif ( $is_form ) {
				$listing_id = $model->get_model()->get_id();
			} else {
				$listing_id = get_the_ID();
			}

			if ( ! $listing_id || ! hivepress()->booking->is_booking_enabled( $listing_id ) ) {
				return $form;
			}
		}


		if ( $is_listing && hivepress()->get_version( 'marketplace' ) ) {
			if ( get_option( 'hp_listing_allow_price_extras' ) ) {
				$fields['price_extras']['fields']['type'] = [
					'type'    => 'select',
					'options' => [
						'' => 'per day',
					],
					'_order'  => 30,
				];
			}
		}
		if ( $is_model ) {
			$form = $fields;
		} else {
			$form['fields'] = $fields;
		}

		return $form;
}

Hi.
In general its fine. Do you have a knowledge how I can amend the Code that only the per booking stays?
And do you know if there is any chance that I amend the “synonym” per booking into something else?
Thanks,
Till

I found that code here on this community by searching the community via keyword extra. But sorry I do not have knowledge of coding.

Try changing the words in the code from per day to per booking both on top and bottom of code, to see if that works.
If not, Hivepress support can you change the above code snippet to per booking instead for him?

As for the second part download the loco translate plugin. Once downloaded go to the plugin section and you can change any text on your website there. I can provide you these steps if you need.

Please try this PHP snippet to leave only the per booking option. If you want to change it to another name then please just change the per booking in the code snippet. If you want to change this name and the calculation logic then unfortunately there is no simple snippet, it requires advanced customization

add_filter(
	'hivepress/v1/models/listing/attributes',
	function($attributes){
		if(isset($attributes['price_extras'])){
			$attributes['price_extras']['edit_field']['fields']['type']['options'] = [
				'per_order' => 'per booking',
			];
		}
		
		return $attributes;
	},
	1000
);

add_filter( 'hivepress/v1/models/listing/fields', 'change_price_extras_custom', 200, 2 );
add_filter( 'hivepress/v1/forms/listing_update', 'change_price_extras_custom', 200, 2 );
add_filter( 'hivepress/v1/meta_boxes/listing_attributes', 'change_price_extras_custom', 200 );
add_filter( 'hivepress/v1/models/vendor/fields', 'change_price_extras_custom', 200, 2 );
add_filter( 'hivepress/v1/forms/vendor_update', 'change_price_extras_custom', 200, 2 );
add_filter( 'hivepress/v1/meta_boxes/vendor_attributes', 'change_price_extras_custom', 200 );

function change_price_extras_custom($form, $model = null){
		$is_form    = strpos( current_filter(), 'form' );
		$is_model   = strpos( current_filter(), 'model' );
		$is_listing = strpos( current_filter(), 'listing' );
		$per_vendor = get_option( 'hp_booking_per_vendor' );

		if ( ! $is_listing && ! $per_vendor ) {
			return $form;
		}
		$fields = [];

		if ( $is_model ) {
			$fields = $form;
		} else {
			$fields = $form['fields'];
		}
		$listing_id = null;

		if ( $is_listing ) {
			if ( $is_model ) {
				$listing_id = $model->get_id();
			} elseif ( $is_form ) {
				$listing_id = $model->get_model()->get_id();
			} else {
				$listing_id = get_the_ID();
			}

			if ( ! $listing_id || ! hivepress()->booking->is_booking_enabled( $listing_id ) ) {
				return $form;
			}
		}


		if ( $is_listing && hivepress()->get_version( 'marketplace' ) ) {
			if ( get_option( 'hp_listing_allow_price_extras' ) ) {
				$fields['price_extras']['fields']['type'] = [
					'type'    => 'select',
					'options' => [
						'per_order' => 'per booking',
					],
					'_order'  => 30,
				];
			}
		}
		if ( $is_model ) {
			$form = $fields;
		} else {
			$form['fields'] = $fields;
		}

		return $form;
}

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