# Listing duration / Time Availability not working correctly

**URL:** <https://community.hivepress.io/t/listing-duration-time-availability-not-working-correctly/2044>\
**Category:** Bookings\
**Tags:** bookings\
**Created:** [September 26, 2022, 7:49am UTC](https://community.hivepress.io/t/listing-duration-time-availability-not-working-correctly/2044 "2022-09-26T07:49:27Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tillos](https://community.hivepress.io/letter_avatar_proxy/v4/letter/t/8797f3/32.png) [@Tillos](https://community.hivepress.io/u/Tillos)\
**Post date:** [September 26, 2022, 7:49am UTC](https://community.hivepress.io/t/listing-duration-time-availability-not-working-correctly/2044/1 "2022-09-26T07:49:27Z")

</div>

When setting up a listing we experience one last topic that seems to be wrong.

1. We have created custom fields for the User / Vendors to create a Listing:

Duration: How long does the Listing is – this is displayed on the Listing page as Duration e.g. 1 HR

Listing available time from: e.g. 12.00

Listing available time to : e.g. 16.00

1. Problem: When the listing is created Hivepress / Wordpress pre populates ten minutes as the duration.

The Display then shows for the User when selecting the time:

12.00 – 12.10

12.10-12.20

Etc.

1. The display should show:

12.00 – 13.00

13.00-14.00 etc

Reasons might be that we have in Wordpress via Hivepress\_Listings two fields with duration and the duration is presetting 10 minutes, see Screenshot.

Important: we have hidden the field to define the break between the Listing ,this is the Support topic:

[**https://community.hivepress.io/t/mark-duration-the-predefined-duration-field-non-mandatory/1503**](https://community.hivepress.io/t/mark-duration-the-predefined-duration-field-non-mandatory/1503)

Can you please help?

 ![image](https://community.hivepress.io/uploads/default/original/2X/f/f74e565924ace0fdd6d3d960c9d78b6c835aec5d.png)

---

<div class="post-metadata">

**Author:** ![ihor](https://community.hivepress.io/user_avatar/community.hivepress.io/ihor/32/5_2.png) [@ihor](https://community.hivepress.io/u/ihor)\
**Post date:** [September 26, 2022, 3:36pm UTC](https://community.hivepress.io/t/listing-duration-time-availability-not-working-correctly/2044/3 "2022-09-26T15:36:08Z")

</div>

Thanks for the details. If you added a custom attribute it will not be linked to the booking restrictions in any way, it can be used just for editing, displaying, and search purposes. There’s already a built-in Booking Slot Duration field, it’s linked to the booking restrictions and it defines the time slot duration, it’s not possible to use a custom attribute for this. Please let me know what’s the purpose of duplicating the built-in Booking Slot Duration attribute and I’ll suggest a solution or a workaround.

---

<div class="post-metadata">

**Author:** ![Tillos](https://community.hivepress.io/letter_avatar_proxy/v4/letter/t/8797f3/32.png) [@Tillos](https://community.hivepress.io/u/Tillos)\
**Post date:** [September 27, 2022, 7:48am UTC](https://community.hivepress.io/t/listing-duration-time-availability-not-working-correctly/2044/4 "2022-09-27T07:48:16Z")

</div>

Hi Ihor,  
Many thanks for your answer. I am bit puzzled how we have set this up. So, what we want to achieve is:

- we would like to show the Duration on the Listing front page and on the listing details sheet.  
This works, see Screenshot.
- and as described previously we would like to achieve that the times (start time and end time ) are displayed correctly.
- From what I understand with the following snippet we have set the duration automatically to 10 minutes, is this correct?  
_[Mark Duration the predefined "Duration" field non mandatory](https://community.hivepress.io/t/mark-duration-the-predefined-duration-field-non-mandatory/1503)_

 ![image](https://community.hivepress.io/uploads/default/original/2X/f/fce4c03ac0ca8e18245c6357ca99e3fc011456be.jpeg)

---

<div class="post-metadata">

**Author:** ![ihor](https://community.hivepress.io/user_avatar/community.hivepress.io/ihor/32/5_2.png) [@ihor](https://community.hivepress.io/u/ihor)\
**Post date:** [September 27, 2022, 12:11pm UTC](https://community.hivepress.io/t/listing-duration-time-availability-not-working-correctly/2044/6 "2022-09-27T12:11:01Z")

</div>

There’s no requirement to set the time slot duration to 10 minutes, you can set it to any duration required for this listing. If the only required change is displaying the time slot duration on the listing page then it may be possible with a code snippet, let me know if this works for you and I’ll share it. Duplicating the slot duration attribute and displaying it will not work because this attribute will not define the actual duration, there’s already a field for this.

---

<div class="post-metadata">

**Author:** ![Tillos](https://community.hivepress.io/letter_avatar_proxy/v4/letter/t/8797f3/32.png) [@Tillos](https://community.hivepress.io/u/Tillos)\
**Post date:** [September 27, 2022, 6:03pm UTC](https://community.hivepress.io/t/listing-duration-time-availability-not-working-correctly/2044/7 "2022-09-27T18:03:54Z")

</div>

Hi Ihor, so what we want to achieve is:

1. Show the duration on the listing and also on the listing overview with a duration icon and
2. we want to be able to show the time slot for the listing 12-13.00 so that the user is able to choose it and request this.

We added a listing attribute to show the duration with icon but we know there is another built in duration field. So the question is if we can use one of them to achieve both?

So again what we want to show:  
Listing duration and then in the drop down time e.g. to say Listing Start 12.00 - Listing End 18.00 , Duration one hour and then there should be availability 12-13.00 , 13-00 -14.00 etc.

Should I send you logins for the WP so that you are able to see how its set up?

---

<div class="post-metadata">

**Author:** ![ihor](https://community.hivepress.io/user_avatar/community.hivepress.io/ihor/32/5_2.png) [@ihor](https://community.hivepress.io/u/ihor)\
**Post date:** [September 28, 2022, 6:27pm UTC](https://community.hivepress.io/t/listing-duration-time-availability-not-working-correctly/2044/9 "2022-09-28T18:27:31Z")

</div>

Sure, you can send temporary WP access via email [support@hivepress.io](mailto:support@hivepress.io) The 2. is already available, the Booking Slot Duration field defines the slot duration and a list of time shots should be displayed if you select a date, if I understand correctly the only requirement is showing the slot duration in the attributes area, near the slot price?

---

<div class="post-metadata">

**Author:** ![Tillos](https://community.hivepress.io/letter_avatar_proxy/v4/letter/t/8797f3/32.png) [@Tillos](https://community.hivepress.io/u/Tillos)\
**Post date:** [September 29, 2022, 8:01am UTC](https://community.hivepress.io/t/listing-duration-time-availability-not-working-correctly/2044/10 "2022-09-29T08:01:28Z")

</div>

Hi Ihor,  
correct it should look like this. I will send it to your email and provide a temporary WP access via mail so that you can check.

 ![image](https://community.hivepress.io/uploads/default/original/2X/b/ba6ebbfc99e186a6d405ed98a9944c62637702bf.png)

---

<div class="post-metadata">

**Author:** ![Tillos](https://community.hivepress.io/letter_avatar_proxy/v4/letter/t/8797f3/32.png) [@Tillos](https://community.hivepress.io/u/Tillos)\
**Post date:** [September 30, 2022, 8:11am UTC](https://community.hivepress.io/t/listing-duration-time-availability-not-working-correctly/2044/11 "2022-09-30T08:11:14Z")

</div>

Thanks for your support and feedback in advance.

---

<div class="post-metadata">

**Author:** ![ihor](https://community.hivepress.io/user_avatar/community.hivepress.io/ihor/32/5_2.png) [@ihor](https://community.hivepress.io/u/ihor)\
**Post date:** [September 30, 2022, 4:41pm UTC](https://community.hivepress.io/t/listing-duration-time-availability-not-working-correctly/2044/13 "2022-09-30T16:41:56Z")

</div>

Sorry for the late reply, I got the email and if the temporary access is valid I’ll check this issue within an hour.

---

<div class="post-metadata">

**Author:** ![ihor](https://community.hivepress.io/user_avatar/community.hivepress.io/ihor/32/5_2.png) [@ihor](https://community.hivepress.io/u/ihor)\
**Post date:** [September 30, 2022, 8:30pm UTC](https://community.hivepress.io/t/listing-duration-time-availability-not-working-correctly/2044/14 "2022-09-30T20:30:08Z")

</div>

Please try this code snippet:

```auto
add_filter(
	'hivepress/v1/models/listing/attributes',
	function( $attributes ) {
		if ( isset( $attributes['booking_slot_duration'] ) ) {
			$attributes['booking_slot_duration']['display_areas'] = ['view_page_primary'];
		}

		return $attributes;
	},
	1000
);

add_filter(
	'hivepress/v1/fields/number/display_value',
	function( $value, $field ) {
		if ( $field->get_name() === 'booking_slot_duration' ) {
			$value = 'Duration: ' . intdiv( $value, 60 ) . ':' . ( $value % 60 );
		}

		return $value;
	},
	1000,
	2
);

```

It displays the slot duration on the listing page without a need to add another Time field. Seems to work [Screenshot by Lightshot](https://prnt.sc/KFIu154eGyok)

---

<div class="post-metadata">

**Author:** ![Tillos](https://community.hivepress.io/letter_avatar_proxy/v4/letter/t/8797f3/32.png) [@Tillos](https://community.hivepress.io/u/Tillos)\
**Post date:** [October 1, 2022, 5:43pm UTC](https://community.hivepress.io/t/listing-duration-time-availability-not-working-correctly/2044/15 "2022-10-01T17:43:27Z")

</div>

Hi Ihor,  
Many thanks for this Code snippet. Now we have a solution for the Calculation. This works and on the listing details also the duration is show. How can show the duration on the front page? There the duration does not show.

 ![image](https://community.hivepress.io/uploads/default/original/2X/c/c2d42843ec3c75f99f3fce66af832b1f3da5b9e7.jpeg)

---

<div class="post-metadata">

**Author:** ![ihor](https://community.hivepress.io/user_avatar/community.hivepress.io/ihor/32/5_2.png) [@ihor](https://community.hivepress.io/u/ihor)\
**Post date:** [October 2, 2022, 8:45am UTC](https://community.hivepress.io/t/listing-duration-time-availability-not-working-correctly/2044/16 "2022-10-02T08:45:05Z")

</div>

Please try changing this line in the snippet:

`$attributes['booking_slot_duration']['display_areas'] = ['view_page_primary'];`

to:

`$attributes['booking_slot_duration']['display_areas'] = ['view_page_primary', 'view_block_secondary'];`

---

<div class="post-metadata">

**Author:** ![Tillos](https://community.hivepress.io/letter_avatar_proxy/v4/letter/t/8797f3/32.png) [@Tillos](https://community.hivepress.io/u/Tillos)\
**Post date:** [October 3, 2022, 5:59pm UTC](https://community.hivepress.io/t/listing-duration-time-availability-not-working-correctly/2044/17 "2022-10-03T17:59:59Z")

</div>

Hi Ihor,  
fantastic. This worked. Now I have only one last question:

1. how can I add the icon “Clock” to the Duration instead of the Synonym “Duration”?  
2: And: can I add the Duration as hh:mm e.g. 01:30 hrs ?

Thanks so much again for your support.

 ![image](https://community.hivepress.io/uploads/default/original/2X/0/010e9beea7b2dafff213d71f1c0fc9e5d551f79c.jpeg)

---

<div class="post-metadata">

**Author:** ![yevhen](https://community.hivepress.io/user_avatar/community.hivepress.io/yevhen/32/23_2.png) [@yevhen](https://community.hivepress.io/u/yevhen)\
**Post date:** [October 4, 2022, 10:38pm UTC](https://community.hivepress.io/t/listing-duration-time-availability-not-working-correctly/2044/19 "2022-10-04T22:38:42Z")

</div>

Please try this PHP snippet but please note that it can require further customization

```auto
add_filter(
	'hivepress/v1/fields/number/display_value',
	function( $value, $field ) {
		if ( $field->get_name() === 'booking_slot_duration' ) {
			$value = '<i class="hp-icon fas fa-fw fa-clock"></i> Duration: ' . intdiv( $value, 60 ) . ':' . ( $value % 60 );
		}

		return $value;
	},
	1000,
	2
);

```

---

<div class="post-metadata">

**Author:** ![Tillos](https://community.hivepress.io/letter_avatar_proxy/v4/letter/t/8797f3/32.png) [@Tillos](https://community.hivepress.io/u/Tillos)\
**Post date:** [October 5, 2022, 11:38am UTC](https://community.hivepress.io/t/listing-duration-time-availability-not-working-correctly/2044/20 "2022-10-05T11:38:02Z")

</div>

HI Yvhen,  
Thanks for your reply. So, its not showing the Clock but it sets all durations to zero which should not be. Any suggestion?

 ![image](https://community.hivepress.io/uploads/default/original/2X/c/c0829eacdbcd9d8c8bd8a4655e0616bfbf56e0bf.jpeg)

---

<div class="post-metadata">

**Author:** ![aqmiami7](https://community.hivepress.io/user_avatar/community.hivepress.io/aqmiami7/32/2069_2.png) [@aqmiami7](https://community.hivepress.io/u/aqmiami7)\
**Post date:** [October 5, 2022, 12:12pm UTC](https://community.hivepress.io/t/listing-duration-time-availability-not-working-correctly/2044/21 "2022-10-05T12:12:06Z")

</div>

```auto
add_filter(
	'hivepress/v1/models/listing/attributes',
	function( $attributes ) {
		if ( isset( $attributes['booking_slot_duration'] ) ) {
			$attributes['booking_slot_duration']['display_areas'] = ['view_page_primary', 'view_block_secondary'];
		}

		return $attributes;
	},
	1000
);

add_filter(
	'hivepress/v1/fields/number/display_value',
	function( $value, $field ) {
		if ( $field->get_name() === 'booking_slot_duration' ) {
			$value = '<i class="hp-icon fas fa-fw fa-clock"></i> Duration: ' . intdiv( $value, 60 ) . ':' . ( $value % 60 );
		}

		return $value;
	},
	1000,
	2
);

```

Hi, use this code instead. It will work with clock and say duration and with this format 1:00

---

<div class="post-metadata">

**Author:** ![Tillos](https://community.hivepress.io/letter_avatar_proxy/v4/letter/t/8797f3/32.png) [@Tillos](https://community.hivepress.io/u/Tillos)\
**Post date:** [October 6, 2022, 9:34am UTC](https://community.hivepress.io/t/listing-duration-time-availability-not-working-correctly/2044/24 "2022-10-06T09:34:56Z")

</div>

Hi,  
Thanks so much. This has worked now. The only last topic I have is :

1. Can I now change the format that its alsways displayed as : 00:00 , e.g. for 1 hour its displayed as 1:00
2. Is there a chance to change also the data entry field so that the user sees 00:00 instead of an empty field to type in minutes?

 ![image](https://community.hivepress.io/uploads/default/original/2X/5/51674f5731242c2aa635eb5cb6caf7f9ccfe50fa.png)

---

<div class="post-metadata">

**Author:** ![yevhen](https://community.hivepress.io/user_avatar/community.hivepress.io/yevhen/32/23_2.png) [@yevhen](https://community.hivepress.io/u/yevhen)\
**Post date:** [October 7, 2022, 10:06pm UTC](https://community.hivepress.io/t/listing-duration-time-availability-not-working-correctly/2044/26 "2022-10-07T22:06:35Z")

</div>

1. Please try this PHP snippet

```auto
add_filter(
	'hivepress/v1/models/listing/attributes',
	function( $attributes ) {
		if ( isset( $attributes['booking_slot_duration'] ) ) {
			$attributes['booking_slot_duration']['display_areas'] = ['view_page_primary', 'view_block_secondary'];
		}

		return $attributes;
	},
	1000
);

add_filter(
	'hivepress/v1/fields/number/display_value',
	function( $value, $field ) {
		if ( $field->get_name() === 'booking_slot_duration' ) {
			$hour = intdiv( $value, 60 );
			
			if($hour < 10){
				$hour = '0'.$hour;
			}
			
			$minute = $value % 60;
			
			if(intval($minute) < 10){
				$minute = '0'.$minute;
			}
			
			$value = '<i class="hp-icon fas fa-fw fa-clock"></i> Duration: ' . $hour . ':' . $minute;
		}

		return $value;
	},
	1000,
	2
);

```

1. Sorry, there’s no simple code snippet - this requires advanced customizations.  
If customizations are required for your site, please try customizing it using the collection of code snippets [Search · user:hivepress · GitHub](https://gist.github.com/search?q=user%3Ahivepress) and other developer resources, or consider hiring someone for custom work [https://fwd.cx/hLhc73mQCD9R](https://fwd.cx/hLhc73mQCD9R)

---

<div class="post-metadata">

**Author:** ![system](https://community.hivepress.io/user_avatar/community.hivepress.io/system/32/13990_2.png) [@system](https://community.hivepress.io/u/system)\
**Post date:** [November 6, 2022, 10:07pm UTC](https://community.hivepress.io/t/listing-duration-time-availability-not-working-correctly/2044/27 "2022-11-06T22:07:22Z")

</div>

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