English (United Kingdom)
Knowledge Base  >  Vik Booking  >  For Developers  >  Booking Process  >  New Reservation Events
1.8.3

do_action( 'vikbooking_before_create_booking_record', object $booking_record, array $rooms, array $tariffs, array $options, array $room_parties )

Fires before a new booking record gets saved onto the database.


Description

Plugins can use this filter to manipulate at runtime the booking information that will be stored onto the database.

It would also be possible to raise an error by throwing an Exception that would prevent the booking from being saved, in case specific validations are required (i.e. spam controls).


Parameters

$booking_record

(object)  The booking record object and related properties ready to be stored onto the database.

$rooms

(array)  List of rooms involved within the new reservation and their related details.

$tariffs

(array)  List of room rates involved within the new reservation and their related details.

$options

(array)  List of options (extra services) involved within the new reservation and their related details.

$room_parties

(array)  List of room party associative arrays, hence adults and children per each room booked.


Example

The example below shows how to identify a possible unwanted reservation that should not be stored. The same hook could be used to manipulate at runtime some of the booking record properties before they get stored onto the database.

/**
 * Trigger action that will run before a new booking record gets saved onto the database.
 * The hook will be triggered only when the booking is being created via front-end.
 * 
 * @param   object  $booking_record    The booking record object and related properties.
 * @param   array   $rooms             List of rooms booked.
 * @param   array   $tariffs           List of room rates for the involved rooms.
 * @param   array   $options           List of room options/extras for the involved rooms.
 * @param   array   $room_parties      List of room party associative arrays containing adults and children per room.
 * 
 * @return  void
 */
add_action('vikbooking_create_cron_jobs_factory', function(object $booking_record, array $rooms, array $tariffs, array $options, array $room_parties)
{
	// check the email address specified by the customer, if any
	if (empty($booking_record->custmail)) {
		// feel free to perform your own validations
		throw new Exception('We do not accept such email address.', 400);
	}

	// manipulate specific properties at runtime
	if (preg_match('/@null\.com$/i', $booking_record->custmail)) {
		// convert the email address before it gets saved
		$booking_record->custmail = 'unknown@email.com';
	}

});
Last Update: 1 week ago
Helpful?
100% of people found this helpful.