Able to limit price extras to per booking only?

Hi community! Wondering if anyone knows how to make it so that users can only add price extras per booking, rather than to let them choose between per booking and per day? TIA

Please try this PHP snippet

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;
}

Oh amazing, thank you!

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