Only keep per place as price extra

Hi, I want to hide all the price extras fields “per place per day”, “per day”, “per booking”, and only keep “per place”. How can I do this? I followed other topics such this one but I did not find a solution: Can you explain price extra types?

Can you please help me find a code snippet to keep only the “per place” option?

Thank you very much!

Please try using the code snippet suggested here Able to limit price extras to per booking only? - #3 by yevhen

I noticed that this one regards “per booking”, how should I customize it to make sure that the only price filter is for “per place”?

Please try this PHP code snippet.

add_filter(
	'hivepress/v1/models/listing/attributes',
	function($attributes){
		if(isset($attributes['price_extras'])){
			$attributes['price_extras']['edit_field']['fields']['type']['options'] = [
				'per_quantity' => 'per place',
			];
		}
		
		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_quantity' => 'per place',
					],
					'_order'  => 30,
				];
			}
		}
		if ( $is_model ) {
			$form = $fields;
		} else {
			$form['fields'] = $fields;
		}

		return $form;
}

Awesome, it worked! Unfortunately though, “per place” is not translated in Italian anymore (I translated my website in Italian with loco translate). I tried to go to LocoTranslate>Plugins>HivePressBookings>"pricing"per place

I tried to translate the field again but the name shown is still “per place” and not “a cliente” as it should be displayed in Italian.

Do you know how can I show the text displayed in Italian again?

Hi,

You must change the code (change ‘per place’ to your title) above to display the translation correctly.

You mean just here?

Hi,

Yes, also, please replace per place in the second snippet.

You mean here?

1 Like

Yes, these two strings must be changed to your translation, and everything should be displayed correctly.

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