Hourly listing display

Hello,

in my listings the hourly booking are listed like : $20 / hour, but when a user selects 2h it display $40 / hour is there a way when the user selects any option it changes the /hour to /total ?

This is the code i have :

add_action('hivepress/v1/models/listing/create', function($listing_id) {
	if(hivepress()->get_version( 'bookings' )){
		update_post_meta($listing_id, 'hp_booking_slot_duration', 60);
	}
});

add_filter(
	'hivepress/v1/models/listing/attributes',
	function( $attributes ) {
		if ( isset($attributes['booking_slot_duration']) ) {
			$attributes['booking_slot_duration']['editable'] = false;
		}
		return $attributes;
	},
	1000
);


add_filter(
	'hivepress/v1/models/listing/fields',
	function( $fields, $listing ) {
		if (hivepress()->get_version( 'bookings' ) && hivepress()->booking->is_time_enabled( $listing->get_id()) && isset( $fields['price'] ) ) {
			$fields['price']['display_template'] = '%value% / hour';
		}
		return $fields;
	},
	1000,
	2
);

If you’re using this snippet to set the format, try adding the condition if (hivepress()->helper->is_rest()).

If this condition returns true, it means the code is being executed during calculation. If it returns false, it means the listing page was opened in the browser.

You can use this condition to apply different formats depending on the context.

1 Like

That worked thanks!

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