Hide Cancel Booking Button x hours before actual booking

Hi there,
I want to hide the cancel booking button on booking page and order dispute button on order page 48 hours before the scheduled booking takes place. What snippet can do that for me?

Best
Andreas

Hi,

Unfortunately, there is no simple snippet for this, but we can provide general recommendations. We recommend overwriting the template parts of this link using a child theme, please check this doc: How to override template parts - HivePress Help Center. And turn this link into a condition inside: $booking->get_start_time().

Thanks a lot Andrii, do you have a rough outline how the condition would look like?

If you override the template part, you can try this one:

if(time() > $booking->get_start_time() - DAY_IN_SECONDS*2) {
//...
}

Thanks Ihor, I will use this.
Any idea where the element is I want to override?

I guess it is this one, but not sure what the folder structure on the child theme should be. hivepress-bookings/booking/… ?

Yes, it’s this one, you can copy it to theme-directory/hivepress/booking/view/page and it’ll override the default template part.

Thanks, got it.

I am not sure why, but I either get only text added or an error on the reservation page.

This gives an error:

<?php
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

if ( in_array( $booking->get_status(), [ 'draft', 'publish' ], true ) || ( $booking->get_status() === 'pending' && get_current_user_id() === $booking->get_user__id() ) ) :
	?>
<?php if(time() < $booking->get_start_time() - 86400*2) {

	<a href="#booking_cancel_modal" class="hp-listing__action hp-listing__action--cancel hp-link">
		<i class="hp-icon fas fa-times"></i>
		<span><?php esc_html_e( 'Cancel Booking', 'hivepress-bookings' ); ?></span>
	</a>
} 
	<?php
endif;

And this just shows the text on the cancel link:

<?php
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

if ( in_array( $booking->get_status(), [ 'draft', 'publish' ], true ) || ( $booking->get_status() === 'pending' && get_current_user_id() === $booking->get_user__id() ) ) :
	?>
if(time() < $booking->get_start_time() - 86400*2) {

	<a href="#booking_cancel_modal" class="hp-listing__action hp-listing__action--cancel hp-link">
		<i class="hp-icon fas fa-times"></i>
		<span><?php esc_html_e( 'Cancel Booking', 'hivepress-bookings' ); ?></span>
	</a>
} 
	<?php
endif;

I managed to fix it with the code below for anybody trying the same thing.
Note the 7 is the amount of days you want this to appear in advance.

<?php

// Exit if accessed directly.

defined( 'ABSPATH' ) || exit;

if (time() < $booking->get_start_time() - 86400*7) {

if (in_array( $booking->get_status(), [ 'draft', 'publish' ], true ) || ( $booking->get_status() === 'pending' && get_current_user_id() === $booking->get_user__id() ) ) :

?>

<a href="#booking_cancel_modal" class="hp-listing__action hp-listing__action--cancel hp-link">

<i class="hp-icon fas fa-times"></i>

<span><?php esc_html_e( 'Cancel Booking', 'hivepress-bookings' ); ?></span>

</a>

<?php

endif;

};

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