Developer API – Create a new booking via function.

To create a new booking, you can use the `wpbc_api_booking_add_new` function.

Example #1:


	$booking    = array(
		'dates' => array( '2027-06-24', '2027-06-24', '2027-06-25', '2027-06-26' ),
		'data'  => array(
			'secondname' => array( 'value' => 'Rika', 'type' => 'text' ),
			'name'       => 'John',
			'email'      => array( 'value' => 'rika@cost.com', 'type' => 'email' ),
		)
	);
	$booking_id = wpbc_api_booking_add_new( $booking['dates'], $booking['data'] );

For the pro version, you can specify the ID of the booking resource (calendar) where you want to save the booking:


	$booking         = array(
		'dates'       => array( '2027-08-24', '2027-08-25', '2027-08-26' ),
		'data'        => array(
			'secondname' => array( 'value' => 'Smith', 'type' => 'text' ),
			'name'       => 'John',
			'rangetime'  => array( 'value' => '14:00 - 16:00', 'type' => 'selectbox-one' ),
			'email'      => array( 'value' => 'rika@cost.com', 'type' => 'email' ),
		),
		'resource_id' => 3,

	);
	$booking_id      = wpbc_api_booking_add_new( $booking['dates'], $booking['data'], $booking['resource_id'] );

Please note that both examples will create new bookings only if the dates (and times, if provided) are available in the destination booking resource (calendar). If you want to create a new booking without checking for date/time availability and create the booking in any case, use the new parameter as shown in this example:


	$booking    = array(
		'dates'       => array( '2027-08-24', '2027-08-25', '2027-08-26' ),
		'data'        => array(
			'rangetime'  => array( 'value' => '14:00 - 16:00', 'type' => 'selectbox-one' ),  // Define booked time-slot.
			'name'       => 'John',                                                          // Simple configuration.
			'secondname' => array( 'value' => 'Smith', 'type' => 'text' ),                   // Advanced configuration.
			'email'      => array( 'value' => 'John@cost.com', 'type' => 'email' ),
		),
		'resource_id' => 3,
		'options'     => array(
			'save_booking_even_if_unavailable' => 1,  // [0 | 1]  if 1 - skip checking if the dates/times are available.
		),
	);
	$booking_id = wpbc_api_booking_add_new( $booking['dates'], $booking['data'], $booking['resource_id'], $booking['options'] );