Listing duration / Time Availability not working correctly

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

Can you please help?

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.

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

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.

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?

Sure, you can send temporary WP access via email 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?

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.

Thanks for your support and feedback in advance.

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

Please try this code snippet:

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

1 Like

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.

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' ];

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.

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

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 Yvhen,
Thanks for your reply. So, its not showing the Clock but it sets all durations to zero which should not be. Any suggestion?

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

1 Like

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?

  1. Please try this PHP snippet
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 and other developer resources, or consider hiring someone for custom work https://fwd.cx/hLhc73mQCD9R

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