# Hide Cancel Booking Button x hours before actual booking

**URL:** <https://community.hivepress.io/t/hide-cancel-booking-button-x-hours-before-actual-booking/9487>\
**Category:** Bookings\
**Tags:** bookings, code\
**Created:** [January 31, 2024, 2:11pm UTC](https://community.hivepress.io/t/hide-cancel-booking-button-x-hours-before-actual-booking/9487 "2024-01-31T14:11:01Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![lehner\_andreas](https://community.hivepress.io/user_avatar/community.hivepress.io/lehner_andreas/32/8465_2.png) [@lehner\_andreas](https://community.hivepress.io/u/lehner_andreas)\
**Post date:** [January 31, 2024, 2:11pm UTC](https://community.hivepress.io/t/hide-cancel-booking-button-x-hours-before-actual-booking/9487/1 "2024-01-31T14:11:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![andrii](https://community.hivepress.io/user_avatar/community.hivepress.io/andrii/32/2951_2.png) [@andrii](https://community.hivepress.io/u/andrii)\
**Post date:** [February 1, 2024, 1:36pm UTC](https://community.hivepress.io/t/hide-cancel-booking-button-x-hours-before-actual-booking/9487/4 "2024-02-01T13:36:49Z")

</div>

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](https://help.hivepress.io/article/155-how-to-override-template-parts). And turn this link into a condition inside: `$booking->get_start_time()`.

---

<div class="post-metadata">

**Author:** ![lehner\_andreas](https://community.hivepress.io/user_avatar/community.hivepress.io/lehner_andreas/32/8465_2.png) [@lehner\_andreas](https://community.hivepress.io/u/lehner_andreas)\
**Post date:** [February 2, 2024, 9:32am UTC](https://community.hivepress.io/t/hide-cancel-booking-button-x-hours-before-actual-booking/9487/5 "2024-02-02T09:32:28Z")

</div>

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

---

<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:** [February 5, 2024, 8:38pm UTC](https://community.hivepress.io/t/hide-cancel-booking-button-x-hours-before-actual-booking/9487/7 "2024-02-05T20:38:14Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![lehner\_andreas](https://community.hivepress.io/user_avatar/community.hivepress.io/lehner_andreas/32/8465_2.png) [@lehner\_andreas](https://community.hivepress.io/u/lehner_andreas)\
**Post date:** [February 20, 2024, 10:09am UTC](https://community.hivepress.io/t/hide-cancel-booking-button-x-hours-before-actual-booking/9487/8 "2024-02-20T10:09:48Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![lehner\_andreas](https://community.hivepress.io/user_avatar/community.hivepress.io/lehner_andreas/32/8465_2.png) [@lehner\_andreas](https://community.hivepress.io/u/lehner_andreas)\
**Post date:** [February 20, 2024, 10:12am UTC](https://community.hivepress.io/t/hide-cancel-booking-button-x-hours-before-actual-booking/9487/9 "2024-02-20T10:12:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lehner\_andreas](https://community.hivepress.io/user_avatar/community.hivepress.io/lehner_andreas/32/8465_2.png) [@lehner\_andreas](https://community.hivepress.io/u/lehner_andreas)\
**Post date:** [February 20, 2024, 11:33am UTC](https://community.hivepress.io/t/hide-cancel-booking-button-x-hours-before-actual-booking/9487/10 "2024-02-20T11:33:12Z")

</div>

> [@ihor](#):
>
> ```auto
> if(time() > $booking->get_start_time() - DAY_IN_SECONDS*2) {
> //...
> }
> 
> ```

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

---

<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:** [February 21, 2024, 11:22am UTC](https://community.hivepress.io/t/hide-cancel-booking-button-x-hours-before-actual-booking/9487/12 "2024-02-21T11:22:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lehner\_andreas](https://community.hivepress.io/user_avatar/community.hivepress.io/lehner_andreas/32/8465_2.png) [@lehner\_andreas](https://community.hivepress.io/u/lehner_andreas)\
**Post date:** [February 22, 2024, 1:55pm UTC](https://community.hivepress.io/t/hide-cancel-booking-button-x-hours-before-actual-booking/9487/13 "2024-02-22T13:55:45Z")

</div>

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:

```auto
<?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:

```auto
<?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;

```

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

---

<div class="post-metadata">

**Author:** ![lehner\_andreas](https://community.hivepress.io/user_avatar/community.hivepress.io/lehner_andreas/32/8465_2.png) [@lehner\_andreas](https://community.hivepress.io/u/lehner_andreas)\
**Post date:** [February 22, 2024, 2:12pm UTC](https://community.hivepress.io/t/hide-cancel-booking-button-x-hours-before-actual-booking/9487/14 "2024-02-22T14:12:17Z")

</div>

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.

```auto
<?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;

};

```

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

---

<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:** [March 23, 2024, 2:12pm UTC](https://community.hivepress.io/t/hide-cancel-booking-button-x-hours-before-actual-booking/9487/15 "2024-03-23T14:12:37Z")

</div>

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