Pending When Occupancy Exceeds Threshold

Automatically set bookings to Pending when the occupancy exceeds a threshold.

Instructions

See “Where do I put snippets?” in our documentation for installation instructions.

Code

Filename: gpb-pending-when-occupancy-exceeds-threshold.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
/**
 * Gravity Perks // Bookings // Pending When Occupancy Exceeds Threshold
 * https://gravitywiz.com/documentation/gp-bookings/
 *
 * Automatically set bookings to Pending when the occupancy exceeds a threshold.
 */
add_action( 'gpb_after_booking_created', function ( $booking, $booking_data, $object, $entry ) {

	// Configuration
	$pending_threshold = 5; // Set the pending threshold
	$target_form_ids   = array( 123 ); // Leave empty to apply to all forms

	if ( empty( $booking ) || ! $booking instanceof \GP_Bookings\Booking || $booking->get_type() !== 'service' ) {
		return;
	}

	if ( ! empty( $target_form_ids ) ) {
		$form_id = $entry && isset( $entry['form_id'] ) ? (int) $entry['form_id'] : 0;
		if ( ! $form_id || ! in_array( $form_id, $target_form_ids, true ) ) {
			return;
		}
	}

	$occupancy = $booking->get_occupancy();
	if ( $occupancy == null ) {
		return;
	}

	if ( $occupancy > $pending_threshold ) {
		$booking->update_status( 'pending', 'Auto-pending due to occupancy threshold', true );
	}
}, 10, 4 );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.