PluginProbe
Booking Calendar / 10.10.1
Booking Calendar v10.10.1
11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 10.11.3 All 202 releases
booking / core / wpbc-dev-api.php

wpbc-dev-api.php in Booking Calendar 10.10.1, at core/wpbc-dev-api.php

721 lines 38.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @version 1.0
4 * @package Booking Calendar
5 * @subpackage Dev API for integration Booking Calendar with third party
6 * @category API
7 *
8 * @author wpdevelop
9 * @link https://wpbookingcalendar.com/
10 * @email info@wpbookingcalendar.com
11 *
12 * @modified 2017-06-24
13 */
14
15 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
16
17 //FixIn: 8.0
18
19 // ---------------------------------------------------------------------------------------------------------------------
20 // Add New Booking
21 // ---------------------------------------------------------------------------------------------------------------------
22 /**
23 * Add New Booking
24 *
25 * @param array $booking_dates // array( '2017-06-24', '2017-06-24', '2017-06-25' );
26 * @param array $booking_data // array(
27 * 'secondname' => array( 'value' => 'Rika' , 'type' => 'text' )
28 * , 'name' => 'Jo' // 'text' field type, if in such format
29 * , 'rangetime' => array( 'value' => '14:00 - 16:00', 'type' => 'selectbox-one' )
30 * , 'email' => array( 'value' => 'rika@cost.com', 'type' => 'email' )
31 * )
32 * @param int $resource_id // Optional. Default: 1
33 * @param type $params // Optional. Default: array(
34 * 'is_send_emeils' => 0
35 * , 'booking_form_type' => ''
36 * , 'wpdev_active_locale' => 'en_US'
37 * , 'is_show_payment_form' => 0
38 * , 'is_edit_booking' => false | array( 'booking_id' => 75, 'booking_type' => 1 )
39 * , 'save_booking_even_if_unavailable' => 0 // 0 | 1 - if 1 then save booking without checking if this date available. Usually save to main booking resource
40 * , 'is_use_booking_recurrent_time' => false
41 * )
42 * @return int|WP_Error - booking ID or WP_Error
43 *
44 *
45 ***********************************************************************************************************************
46 * Notes!
47 * If you need to book for specific time, then its have to be in appropriate field(s) at $booking_data - booking form. In $booking_dates times have been sliced.
48 * It does not check about booked | available dates in calendar with capacity > 1 !!!!
49 * If the single booking resource booked for specific dates and settings have activated "Checking to prevent double booking, during submitting booking" then system just DIE
50 ***********************************************************************************************************************
51 *
52 * Examples:
53 *
54 - AddSimple
55 $booking = array(
56 'dates' => array( '2017-06-24', '2017-06-24', '2017-06-25', '2017-06-26' )
57 , 'data' => array(
58 'secondname' => array( 'value' => 'Rika', 'type' => 'text' )
59 , 'name' => 'John'
60 , 'email' => array( 'value' => 'rika@cost.com', 'type' => 'email' )
61 )
62 );
63 $booking_id = wpbc_api_booking_add_new( $booking[ 'dates' ], $booking[ 'data' ] );
64
65 - Resource
66 $booking = array(
67 'dates' => array( '2017-06-24', '2017-06-24', '2017-06-25', '2017-06-26' )
68 , 'data' => array(
69 'secondname' => array( 'value' => 'Rika', 'type' => 'text' )
70 , 'name' => 'JoNNNNNNNNNN'
71 , 'rangetime' => array( 'value' => '14:00 - 16:00', 'type' => 'selectbox-one' )
72 , 'email' => array( 'value' => 'rika@cost.com', 'type' => 'email' )
73 )
74 , 'resource_id' => 3
75
76 );
77 $booking_id = wpbc_api_booking_add_new( $booking[ 'dates' ], $booking[ 'data' ], $booking[ 'resource_id' ] );
78
79
80 - Edit:
81 $booking = array(
82 'dates' => array( '2017-06-24', '2017-06-24', '2017-06-25', '2017-06-28' )
83 , 'data' => array(
84 'secondname' => array( 'value' => 'Rika', 'type' => 'text' )
85 , 'name' => 'BoBy'
86 , 'rangetime' => array( 'value' => '14:00 - 16:00', 'type' => 'selectbox-one' )
87 , 'email' => array( 'value' => 'rika@cost.com', 'type' => 'email' )
88 )
89 , 'resource_id' => 3
90 , 'params' => array( 'is_edit_booking' => array( 'booking_id' => 79, 'booking_type' => 3 ) )
91
92 );
93 $booking_id = wpbc_api_booking_add_new( $booking[ 'dates' ], $booking[ 'data' ], $booking[ 'resource_id' ], $booking[ 'params' ] );
94 *
95 */
96 function wpbc_api_booking_add_new( $booking_dates, $booking_data, $resource_id = 1, $params = array() ) {
97
98 /*
99 // Dates in format: 'Y-m-d'
100 $booking_dates = array( '2017-06-24', '2017-06-24', '2017-06-25' );
101
102 // Booking Form params
103 $booking_data = array(
104 'secondname' => array( 'value' => 'Rika' , 'type' => 'text' )
105 , 'rangetime' => array( 'value' => '14:00 - 16:00', 'type' => 'selectbox-one' )
106 , 'email' => array( 'value' => 'rika@cost.com', 'type' => 'email' )
107 );
108 // Booking resource ID
109 $resource_id = 1;
110 */
111
112 // Other params
113 $defaults = array(
114 'is_send_emeils' => 0
115 , 'booking_form_type' => '' // custom_form_name
116 , 'wpdev_active_locale' => 'en_US' // locale
117 , 'is_show_payment_form' => 0 // Parameters for adding booking in the HTML:
118 , 'is_edit_booking' => false // array( 'booking_id' => 75, 'booking_type' => 1 ) // Update Booking params
119 , 'is_use_booking_recurrent_time' => ( 'On' === get_bk_option( 'booking_recurrent_time' ) )
120 );
121 $params = wp_parse_args( $params, $defaults );
122
123
124 // booking resource ID
125 $resource_id = intval( $resource_id );
126 $resource_id = ( empty( $resource_id ) ? 1 : $resource_id );
127 $params[ 'bktype' ] = $resource_id;
128
129
130 // Dates ///////////////////////////////////////////////////////////////////////////////////////////////////////////
131 $booking_dates = array_map( 'strtotime', $booking_dates ); // Array ( [0] => 1498262400 [1] => 1498348800 )
132 sort( $booking_dates ); // Sort
133 $booking_dates = array_unique( $booking_dates ); // Remove Duplicates
134 $dates_formats = array_fill( 0, count( $booking_dates ), "d.m.Y" ); // Array ( [0] => d.m.Y [1] => d.m.Y )
135 $booking_dates = array_map( 'date_i18n', $dates_formats , $booking_dates ); // Array ( [0] => 24.06.2017 [1] => 25.06.2017 )
136 $booking_dates = implode(', ', $booking_dates); // 24.06.2017, 25.06.2017
137 $params[ 'dates' ] = $booking_dates;
138
139
140 // Booking Form ////////////////////////////////////////////////////////////////////////////////////////////////////
141 $booking_form = array();
142 foreach ( $booking_data as $field_name => $field_params ) {
143
144 if ( is_array( $field_params ) ) {
145
146 $booking_form_field = array( $field_params['type'], $field_name . $resource_id, $field_params['value'] );
147 } else { // value just string
148 $booking_form_field = array( 'text', $field_name . $resource_id, $field_params );
149 }
150 $booking_form_field[ 0 ] = str_replace( array( '^', '~' ), array( 'curret', 'tilde' ), $booking_form_field[ 0 ] ); // replace to temp symbols
151 $booking_form_field[ 1 ] = str_replace( array( '^', '~' ), array( 'curret', 'tilde' ), $booking_form_field[ 1 ] );
152 $booking_form_field[ 2 ] = str_replace( array( '^', '~' ), array( 'curret', 'tilde' ), $booking_form_field[ 2 ] );
153
154 $booking_form_field = implode( '^' , $booking_form_field );
155 $booking_form []= $booking_form_field;
156 }
157 $booking_form = implode( '~' , $booking_form );
158 $params[ 'form' ] = $booking_form;
159
160
161 $resource_id = $params['bktype'];
162
163
164 $booking_hash = '';
165 if ( ! empty( $params['is_edit_booking'] ) ) {
166
167 $hash__arr = wpbc_hash__get_booking_hash__resource_id( $params['is_edit_booking']['booking_id'] ); // Get new booking hash
168
169 if ( ! empty( $hash__arr ) ) {
170 list( $booking_hash, $resource_id ) = $hash__arr;
171 }
172 }
173
174
175 // Create a new booking
176 $request_save_params = array(
177 'resource_id' => $resource_id, // 2
178 'dates_ddmmyy_csv' => $params[ 'dates' ], // '04.10.2023, 05.10.2023, 06.10.2023'
179 'form_data' => $params[ 'form' ], // 'text^cost_hint2^150.00฿~selectbox-multiple^rangetime2[]^14:00...'
180 'booking_hash' => $booking_hash, // 'sdfsf34534rf'
181 'custom_form' => $params['booking_form_type'], // 'custom_form_name'
182 'is_emails_send' => $params['is_send_emeils'], // 0 | 1
183 'is_show_payment_form' => intval( $params['is_show_payment_form'] ), // 0 | 1
184 // 'request_uri' => $_SERVER['HTTP_REFERER']
185 // 'user_id' => wpbc_get_current_user_id()
186 'sync_gid' => ( ( ! empty( $params['sync_gid'] ) ) ? $params['sync_gid'] : '' ),
187 'is_approve_booking' => ( ( ! empty( $params['is_approve_booking'] ) ) ? $params['is_approve_booking'] : 0 ), // Auto approve booking ??
188 'save_booking_even_if_unavailable' => ( ( ! empty( $params['save_booking_even_if_unavailable'] ) ) ? $params['save_booking_even_if_unavailable'] : 0 ), // Force saving booking without checking
189 'is_use_booking_recurrent_time' => intval( $params['is_use_booking_recurrent_time'] )
190 );
191
192 $booking_save_arr = wpbc_booking_save( $request_save_params );
193 if ( 'ok' === $booking_save_arr['ajx_data']['status'] ) { // Everything Cool :) - booking has been duplicated
194 $booking_id = $booking_save_arr['booking_id'];
195 } else { // Error
196 $booking_id = 0;
197 // Error message: $booking_save_arr['ajx_data']['ajx_after_action_message'];
198 return new WP_Error( 'wpbc_api_booking_add_new__error', $booking_save_arr['ajx_data']['ajx_after_action_message'] );
199 }
200
201 return $booking_id;
202 }
203
204 // ---------------------------------------------------------------------------------------------------------------------
205 // Is Date Booked ?
206 // ---------------------------------------------------------------------------------------------------------------------
207 /**
208 * Check if dates available in specific resource
209 *
210 * @param array $booking_dates // [ "2023-09-27 23:30:01","2023-09-28 00:00:00","2023-09-29 00:59:52" ] Range List of Dates in MySQL format, like: array( '2017-06-23 14:00:01', '2017-06-24 00:00:00', '2017-06-25', '2017-06-26 12:00:02' );
211 * @param int $resource_id // 9 Optional. Default: 1
212 * @param array $params // [ 'is_use_booking_recurrent_time' => false ] Optional. Default: array( ) -- For future improvement
213 *
214 * @return bool // true | false
215 *
216 * Examples:
217 *
218 * $booking = array(
219 * 'dates' => array( '2017-06-23 14:00:01', '2017-06-24 00:00:00', '2017-06-25', '2017-06-26 12:00:02' )
220 * , 'resource_id' => 1
221 * , 'params' => array( 'is_use_booking_recurrent_time' => false )
222 * );
223 * $result = wpbc_api_is_dates_booked( $booking[ 'dates' ], $booking[ 'resource_id' ], $booking[ 'params' ] );
224 */
225 function wpbc_api_is_dates_booked( $booking_dates, $resource_id = 1, $params = array() ) {
226
227 $defaults = array(
228 'is_use_booking_recurrent_time' => ( 'On' === get_bk_option( 'booking_recurrent_time' ) )
229 );
230 $params = wp_parse_args( $params, $defaults );
231
232
233 // Convert: ["2023-09-27 23:30:01","2023-09-28 00:00:00","2023-09-29 00:59:52"] -> [ "2023-10-18", "2023-10-25", "2023-11-25" ]
234 $dates_only_sql_arr = array_map( function ( $value ) {
235 $value_arr = explode( ' ', $value );
236 return $value_arr[0];
237 }, $booking_dates );
238
239 // Convert: ["2023-09-27 23:30:01","2023-09-28 00:00:00","2023-09-29 00:59:52"] -> [ 36000, 39600 ]
240 $time_as_seconds_arr = array( $booking_dates[0], $booking_dates[ ( count( $booking_dates ) - 1 ) ], );
241 $time_as_seconds_arr = array_map( function ( $value ) {
242 $value_arr = explode( ' ', $value );
243 $time_sec = wpbc_transform__24_hours_his__in__seconds( $value_arr[1] );
244 return $time_sec;
245 }, $time_as_seconds_arr );
246
247
248 /**
249 * Get slots [] where we can save booking = [ 'resources_in_dates' => [ 2023-10-18 = [ 2, 12, 10, 11 ]
250 * 2023-10-19 = [ 2, 12, 10, 11 ]
251 * 2023-10-20 = [ 2, 12, 10, 11 ]
252 * ],
253 * 'time_to_book' => [ "14:00:01" , "12:00:01" ],
254 * 'result' => 'ok'
255 * 'main__resource_id' => 2
256 * ]
257 * OR
258 * [ 'result' => 'error', 'message' => 'Booking can not be saved ...' ]
259 */
260 $server_request_uri = ( ( isset( $_SERVER['REQUEST_URI'] ) ) ? sanitize_text_field( $_SERVER['REQUEST_URI'] ) : '' ); /* phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash */ /* FixIn: sanitize_unslash */
261 $server_http_referer_uri = ( ( isset( $_SERVER['HTTP_REFERER'] ) ) ? sanitize_text_field( $_SERVER['HTTP_REFERER'] ) : '' ); /* phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash */ /* FixIn: sanitize_unslash */
262 $where_to_save_booking = wpbc__where_to_save_booking( array(
263 'resource_id' => $resource_id, // 2
264 'skip_booking_id' => '', // '', | 125 if edit booking
265 'dates_only_sql_arr' => $dates_only_sql_arr, // [ "2023-10-18", "2023-10-25", "2023-11-25" ]
266 'time_as_seconds_arr' => $time_as_seconds_arr, // [ 36000, 39600 ]
267 'how_many_items_to_book' => 1, // 1
268 'request_uri' => ( ( ( defined( 'DOING_AJAX' ) ) && ( DOING_AJAX ) ) ? $server_http_referer_uri : $server_request_uri ), // front-end: $server_request_uri | ajax: $_SERVER['HTTP_REFERER'] // It different in Ajax requests. It's used for change-over days to detect for exception at specific pages, // 'http://beta/resource-id2/'
269 'as_single_resource' => true, // false
270 'is_use_booking_recurrent_time' => $params['is_use_booking_recurrent_time']
271 ) );
272
273 if ( 'ok' != $where_to_save_booking['result'] ) {
274 $is_dates_times_unavailable = true;
275 /**
276 *
277 $ajx_data_arr['status'] = 'error';
278 $ajx_data_arr['status_error'] = 'booking_can_not_save';
279 $ajx_data_arr['ajx_after_action_message'] = $where_to_save_booking['message'];
280 $ajx_data_arr['ajx_after_action_message_status'] = 'warning';
281 return array( 'ajx_data' => $ajx_data_arr );
282 */
283 } else {
284 $is_dates_times_unavailable = false;
285 }
286
287 return $is_dates_times_unavailable;
288 }
289
290 // ---------------------------------------------------------------------------------------------------------------------
291 // Get Bookings Array - [Listing]
292 // ---------------------------------------------------------------------------------------------------------------------
293 /**
294 * Get bookings array from Booking Calendar
295 *
296 * @param aray $params
297 * @return array
298 ( [bookings] => Array (
299 [2661] => stdClass Object (
300 [booking_id] => 2661
301 [trash] => 0
302 [sync_gid] => 5t3ogfsb3tqj09po7fiou6hh60@google.com
303 [is_new] => 1
304 [status] =>
305 [sort_date] => 2017-08-07 20:00:01
306 [modification_date] => 2017-07-08 11:54:03
307 [form] => text^name4^Event (timezone Pacific GMT-07:00)~....
308 [hash] => 69afc11e2ce86044dd55fbddf582ce66
309 [booking_type] => 4
310 [remark] =>
311 [cost] => 51.98
312 [pay_status] => 149950764311
313 [pay_request] => 0
314 [dates] => Array (
315 [0] => stdClass Object (
316 [booking_id] => 2661
317 [booking_date] => 2017-08-07 20:00:01
318 [approved] => 0
319 [type_id] => )
320 [1] => stdClass Object (
321 [booking_id] => 2661
322 [booking_date] => 2017-08-08 00:00:00
323 [approved] => 0
324 [type_id] =>
325 )
326 )
327 [dates_short] => Array (
328 [0] => 2017-08-07 20:00:01
329 [1] => -
330 [2] => 2017-08-08 00:00:00 )
331 [form_show] => 'First Name: John....'
332 [form_data] => Array (
333 [email] => ics@beta
334 [name] => Event (timezone Pacific GMT-07:00)
335 [secondname] =>
336 [visitors] => 1
337 [coupon] =>
338 [_all_] => Array (
339 [name4] => Event (timezone Pacific GMT-07:00)
340 [details4] => 8/7/2017 1:00pm TO 3:30pm 8/8/2017 (GMT-07:00) Pacific Time
341 [email4] => ics@beta
342 [rangetime4] => 20:00 - 00:00
343 [sync_gid4] => 5t3ogfsb3tqj09po7fiou6hh60@google.com
344 )
345 [_all_fields_] => Array (
346 [name] => Event (timezone Pacific GMT-07:00)
347 [details] => 8/7/2017 1:00pm TO 3:30pm 8/8/2017 (GMT-07:00) Pacific Time
348 [email] => ics@beta
349 [rangetime] => 20:00 - 00:00
350 [sync_gid] => 5t3ogfsb3tqj09po7fiou6hh60@google.com
351 [booking_resource_id] => 4
352 [resource_id] => 4
353 [type_id] => 4
354 [type] => 4
355 [resource] => 4
356 [booking_id] => 2661
357 [resource_title] => stdClass Object (
358 [booking_type_id] => 4
359 [title] => Apartment#3
360 [users] => 1
361 [import] => some_email@group.calendar.google.com
362 [cost] => 25.99
363 [default_form] => standard
364 [prioritet] => 40
365 [parent] => 0
366 [visitors] => 1
367 [id] => 4
368 [count] => 1
369 [ID] => 4
370 )
371 )
372 [rangetime] => 20:00 - 00:00
373 )
374 [dates_short_id] => Array (
375 [0] =>
376 [1] =>
377 [2] =>
378 )
379 )
380 ....
381 )
382 [resources] => Array (
383 [4] => stdClass Object
384 (
385 [booking_type_id] => 4
386 [title] => Apartment#3
387 [users] => 1
388 [import] => some_email@group.calendar.google.com
389 [cost] => 25.99
390 [default_form] => standard
391 [prioritet] => 40
392 [parent] => 0
393 [visitors] => 1
394 [id] => 4
395 [count] => 1
396 [ID] => 4
397 )
398 ....
399 )
400 [bookings_count] => 2
401 [page_num] => 1
402 [count_per_page] => 100000
403 )
404 *
405 */
406 function wpbc_api_get_bookings_arr( $params = array() ) {
407
408 // Start Date of getting bookings
409 $real_date = strtotime( 'now' );
410 $wh_booking_date = date_i18n( "Y-m-d", $real_date ); // '2012-12-01';
411
412 // End date of getting bookings
413 $real_date = strtotime( '+1 year' );
414 $wh_booking_date2 = date_i18n( "Y-m-d", $real_date ); // '2013-02-31';
415
416 // params
417 $defaults = array(
418 'wh_booking_type' => '1'
419 , 'wh_approved' => ''
420 , 'wh_booking_id' => ''
421 , 'wh_is_new' => ''
422 , 'wh_pay_status' => 'all'
423 , 'wh_keyword' => ''
424 , 'wh_booking_date' => $wh_booking_date
425 , 'wh_booking_date2' => $wh_booking_date2
426 , 'wh_modification_date' => '3'
427 , 'wh_modification_date2' => ''
428 , 'wh_cost' => ''
429 , 'wh_cost2' => ''
430 , 'or_sort' => ''
431 , 'page_num' => '1'
432 , 'wh_trash' => '' // '' | trash | any // FixIn: 8.0.2.8.
433 , 'limit_hours' => '0,24'
434 , 'only_booked_resources' => 0
435 , 'page_items_count' => '100000'
436 );
437 $params = wp_parse_args( $params, $defaults );
438
439 $bookings_arr = wpbc_get_bookings_objects( $params );
440
441 return $bookings_arr;
442 }
443
444 // FixIn: 8.7.6.4.
445 /**
446 * Get Booking Data as array of properties
447 *
448 * @param string $booking_id - digit '11' or comma separated '11,19,12'
449 *
450 * @return array
451 */
452 function wpbc_api_get_booking_by_id( $booking_id = '' ) {
453
454 global $wpdb;
455 $booking_id = wpbc_clean_digit_or_csd( $booking_id );
456
457 $slct_sql = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}booking as b left join {$wpdb->prefix}bookingdates as bd on (b.booking_id = bd.booking_id) WHERE b.booking_id IN (%s) LIMIT 0,1", $booking_id );
458
459 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
460 $slct_sql_results = $wpdb->get_results( $slct_sql, ARRAY_A );
461
462 $data = array();
463
464 if ( count( $slct_sql_results ) > 0 ) {
465 $data = $slct_sql_results[0];
466 $formdata_array = explode( '~', $data['form'] );
467
468 $formdata_array_count = count( $formdata_array );
469 for ( $i = 0; $i < $formdata_array_count; $i ++ ) {
470
471 if ( empty( $formdata_array[ $i ] ) ) {
472 continue;
473 }
474 $elemnts = explode( '^', $formdata_array[ $i ] );
475 $type = $elemnts[0];
476 $element_name = $elemnts[1];
477 $value = $elemnts[2];
478 $value = nl2br( $value );
479 $data['formdata'][ $element_name ] = $value;
480 }
481 }
482 return $data;
483 }
484
485 // FixIn: 8.7.7.3.
486 /**
487 * Get booking form fields in Booking Calendar Free version
488 * @return array
489 */
490 function wpbc_get_form_fields_free() {
491 $obj = array();
492 if ( function_exists( 'wpbc_simple_form__db__get_visual_form_structure' ) ) {
493
494 $form_fields = wpbc_simple_form__db__get_visual_form_structure();
495
496 foreach ( $form_fields as $field ) {
497 // FixIn: 8.7.8.7.
498 if ( ( ! empty( $field['name'] ) )
499 && ( ! empty( $field['label'] ) )
500 && ( ! in_array( $field['type'], array(
501 'captcha',
502 'submit'
503 ) ) )
504 ) {
505 $obj[ $field['name'] ] = $field['label'];
506 }
507 }
508 }
509 return $obj;
510 }
511
512
513 /**
514 * Hook for definition of the different DEFAULT parameters for single booking resource, that was just created by user at the Booking > Resources page.
515 * In this example, you need to uncomment this line:
516 * //add_action('wpbc_resource_created','wpbc_resource_created__add_other_params', 10, 1);
517 * And the following function add Duration-Based Costs for the exist booking resources and some Search Filters.
518 */
519 //add_action('wpbc_resource_created','wpbc_resource_created__add_other_params', 10, 1);
520 function wpbc_resource_created__add_other_params( $resource_id ) {
521
522 global $wpdb;
523
524 // -----------------------------------------------------------------------------------------------------------------
525 // Add default 'Duration-Based Costs'
526 // -----------------------------------------------------------------------------------------------------------------
527 $wp_queries = array();
528
529 //WP Booking Calendar > Prices > Daily Costs page -> section Duration-Based Costs
530 $season_id = 4;
531 $meta_arr = array(
532 array( 'active' => 'On', 'type' => 'summ', 'from' => 7, 'to' => 14, 'cost' => 90, 'cost_apply_to' => '%' ,'season_filter' => $season_id ),
533 array( 'active' => 'On', 'type' => '>', 'from' => 8, 'to' => 27, 'cost' => 90, 'cost_apply_to' => '%' ,'season_filter' => $season_id ),
534 array( 'active' => 'On', 'type' => 'summ', 'from' => 28, 'to' => 14, 'cost' => 75, 'cost_apply_to' => '%' ,'season_filter' => $season_id ),
535 array( 'active' => 'On', 'type' => '>', 'from' => 29, 'to' => 60, 'cost' => 75, 'cost_apply_to' => '%' ,'season_filter' => $season_id ),
536 array( 'active' => 'On', 'type' => '=', 'from' => 'LAST', 'to' => 14, 'cost' => 0, 'cost_apply_to' => 'fixed' ,'season_filter' => $season_id )
537 );
538 $meta_str = maybe_serialize($meta_arr);
539 $wp_queries[] = "INSERT INTO {$wpdb->prefix}booking_types_meta ( type_id, meta_key, meta_value ) VALUES ( {$resource_id}, 'costs_depends', '{$meta_str}' );";
540
541 // // WP Booking Calendar > Prices > Daily Costs page -> section Seasonal Pricing
542 // $meta_str = "a:3:{s:6:\"filter\";a:3:{i:3;s:3:\"Off\";i:2;s:3:\"Off\";i:1;s:2:\"On\";}s:4:\"rate\";a:3:{i:3;s:1:\"0\";i:2;s:1:\"0\";i:1;s:3:\"200\";}s:9:\"rate_type\";a:3:{i:3;s:1:\"%\";i:2;s:1:\"%\";i:1;s:1:\"%\";}}";
543 // $wp_queries[] = "INSERT INTO {$wpdb->prefix}booking_types_meta ( type_id, meta_key, meta_value ) VALUES ( {$resource_id}, 'rates', '{$meta_str}' );";
544 //
545 // //WP Booking Calendar > Availability > Season Availability page
546 // $meta_str = "a:2:{s:7:\"general\";s:2:\"On\";s:6:\"filter\";a:3:{i:3;s:3:\"Off\";i:2;s:2:\"On\";i:1;s:3:\"Off\";}}";
547 // $wp_queries[] = "INSERT INTO {$wpdb->prefix}booking_types_meta ( type_id, meta_key, meta_value ) VALUES ( {$resource_id}, 'availability', '{$meta_str}' );";
548
549 foreach ( $wp_queries as $wp_q ) {
550 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
551 $wpdb->query( $wp_q );
552 }
553
554 // -----------------------------------------------------------------------------------------------------------------
555 // Add default 'Searchable Filters':
556 // -----------------------------------------------------------------------------------------------------------------
557 // Get search options for all booking resources
558 $search_options_arr = wpbc_searchable_resources__get_all_options();
559
560 // Booking Calendar Business Large version
561 $demo_examples = array();
562 $demo_examples[ $resource_id ] = array();
563 $demo_examples[ $resource_id ]['is_searchable'] = 'On';
564 // $demo_examples[ $resource_id ]['title'] = 'General Consultation';
565 // $demo_examples[ $resource_id ]['url'] = get_site_url() . '/demo/service-a/#main';
566 // $demo_examples[ $resource_id ]['picture'] = get_site_url() . '/demo_assets/service-a.jpg';
567 // $demo_examples[ $resource_id ]['description'] = '...';
568 $demo_examples[ $resource_id ]['options'] = 'neighborhood^=^La Ecovilla~housing_type^=^Entire home~price_range^=^$150-$199~bedrooms^<=^1~my_contribution^=^1';
569
570 foreach ( $demo_examples as $res_id => $res_options ) {
571 $search_options_arr[ $res_id ] = $res_options;
572 }
573 wpbc_searchable_resources__save_all_options( $search_options_arr );
574
575 }
576
577
578 /**
579 * DEPRECATED :: Hook action after creation new booking
580 * @param int $booking_id
581 * @param int $resource_id
582 * @param string $str_dates__dd_mm_yyyy - "30.02.2014, 31.02.2014, 01.03.2014"
583 * @param array $times_array - array($start_time, $end_time )
584 * @param string $booking_form
585 function your_cust_func_add_new_booking( $booking_id, $resource_id, $str_dates__dd_mm_yyyy, $times_array , $booking_form ) {
586
587 }
588 add_action( 'show_payment_forms__for_ajax', 'your_cust_func_add_new_booking', 100, 5 );
589 *
590 Previously: add_action( 'wpdev _new_booking', 'your_cust_func_add_new_booking', 100, 5 );
591 */
592
593 /**
594 * NEW :: Hook action after creation / edit bookings
595 *
596 * How to use this hook?
597 *
598 * Add code similar to this in your functions.php file in your theme, or in some other php file:
599 *
600 * // Track adding new booking
601 * //
602 * // @param $params = array (
603 * 'str_dates__dd_mm_yyyy' => '08.10.2023,09.10.2023,10.10.2023,11.10.2023',
604 * 'booking_id' => 254,
605 * 'resource_id' => 11, // child or parent or single
606 * 'initial_resource_id' => 2, // parent or single
607 * 'form_data' => 'text^selected_short_dates_hint11^Sun...',
608 * 'times_array' => array ( array ( '14', '00', '01' ), array( '12', '00', '02' ) ),
609 * 'is_edit_booking' => 0,
610 * 'custom_form' => '',
611 * 'is_duplicate_booking' => 0,
612 * 'is_from_admin_panel' => false,
613 * 'is_show_payment_form' => 1
614 * )
615 * function my_booking_tracking( $params ){
616 * // Your code here
617 * ?><!-- Google Code for Booking Conversion Page -->
618 * <script type="text/javascript">
619 * // Insert bellow your Google Conversion Code
620 * </script><?php
621 * }
622 * add_action( 'wpbc_track_new_booking', 'my_booking_tracking' );
623 *
624 *
625 *
626 * Useful hook booking edit tracking
627 *
628 * Add code similar to this in your functions.php file in your theme, or in some other php file:
629 *
630 * // Track edit existing booking
631 * //
632 * // @param $params = array (
633 * 'str_dates__dd_mm_yyyy' => '08.10.2023,09.10.2023,10.10.2023,11.10.2023',
634 * 'booking_id' => 254,
635 * 'resource_id' => 11, // child or parent or single
636 * 'initial_resource_id' => 2, // parent or single
637 * 'form_data' => 'text^selected_short_dates_hint11^Sun...',
638 * 'times_array' => array ( array ( '14', '00', '01' ), array( '12', '00', '02' ) ),
639 * 'is_edit_booking' => 1,
640 * 'custom_form' => '',
641 * 'is_duplicate_booking' => 0,
642 * 'is_from_admin_panel' => false,
643 * 'is_show_payment_form' => 1
644 * )
645 * function my_edit_booking_tracking( $params ){
646 * // Your code here
647 * ?><!-- Google Code for Booking Conversion Page -->
648 * <script type="text/javascript">
649 * // Insert bellow your Google Conversion Code
650 * </script><?php
651 * }
652 * add_action( 'wpbc_track_edit_booking', 'my_edit_booking_tracking' );
653 */
654
655 /**
656 * Hook action after approving of booking: do_action( 'wpbc_booking_approved' , $booking_id , $is_approved_dates );
657 * @param int/string $booking_id - can be '1' or 99 or comma separated ID of bookings: '10,22,45'
658 * @param int/string $is_approved_dates - '1' | '0' | 1 | 0 1 -approved, 0 - pending
659 function your_cust_func_wpbc_booking_approved( $booking_id, $is_approved_dates ) {
660
661 }
662 add_action( 'wpbc_booking_approved', 'your_cust_func_wpbc_booking_approved', 100, 2 ); // FixIn: 8.7.6.1.
663 */
664
665 /**
666 * Hook action after trash of booking:
667 * do_action( 'wpbc_booking_trash', $booking_id, $is_trash ); // FixIn: 8.7.6.2.
668 */
669
670 /**
671 * Hook action after delete of booking:
672 * do_action( 'wpbc_booking_delete', $approved_id_str ); // FixIn: 8.7.6.3.
673 */
674
675 /**
676 * Hooks in new Booking Listing page for different actions:
677 * // FixIn: 9.5.3.3.
678 do_action( 'wpbc_set_booking_locale', $params, $action_result ); // where $params is array, which contain $params['booking_id'], and $action_result array and have $action_result['after_action_result'], which contains a boolean value of the result of an operation.
679 do_action( 'wpbc_set_booking_pending', $params, $action_result ); // where $params is array, which contain $params['booking_id'], and $action_result array and have $action_result['after_action_result'], which contains a boolean value of the result of an operation.
680 do_action( 'wpbc_set_booking_approved' $params, $action_result ); // where $params is array, which contain $params['booking_id'], and $action_result array and have $action_result['after_action_result'], which contains a boolean value of the result of an operation.
681 do_action( 'wpbc_move_booking_to_trash' $params, $action_result ); // where $params is array, which contain $params['booking_id'], and $action_result array and have $action_result['after_action_result'], which contains a boolean value of the result of an operation.
682 do_action( 'wpbc_restore_booking_from_trash' $params, $action_result ); // where $params is array, which contain $params['booking_id'], and $action_result array and have $action_result['after_action_result'], which contains a boolean value of the result of an operation.
683 do_action( 'wpbc_delete_booking_completely' $params, $action_result ); // where $params is array, which contain $params['booking_id'], and $action_result array and have $action_result['after_action_result'], which contains a boolean value of the result of an operation.
684 do_action( 'wpbc_set_booking_as_read' $params, $action_result ); // where $params is array, which contain $params['booking_id'], and $action_result array and have $action_result['after_action_result'], which contains a boolean value of the result of an operation.
685 do_action( 'wpbc_set_booking_as_unread' $params, $action_result ); // where $params is array, which contain $params['booking_id'], and $action_result array and have $action_result['after_action_result'], which contains a boolean value of the result of an operation.
686
687 do_action( 'wpbc_set_booking_note' $params, $action_result ); // where $params is array, which contain $params['booking_id'], and $action_result array and have $action_result['after_action_result'], which contains a boolean value of the result of an operation.
688 do_action( 'wpbc_change_booking_resource' $params, $action_result ); // where $params is array, which contain $params['booking_id'], and $action_result array and have $action_result['after_action_result'], which contains a boolean value of the result of an operation.
689
690 do_action( 'wpbc_set_payment_status' $params, $action_result ); // where $params is array, which contain $params['booking_id'], and $action_result array and have $action_result['after_action_result'], which contains a boolean value of the result of an operation.
691 do_action( 'wpbc_set_booking_cost' $params, $action_result ); // where $params is array, which contain $params['booking_id'], and $action_result array and have $action_result['after_action_result'], which contains a boolean value of the result of an operation.
692 do_action( 'wpbc_send_payment_request' $params, $action_result ); // where $params is array, which contain $params['booking_id'], and $action_result array and have $action_result['after_action_result'], which contains a boolean value of the result of an operation.
693 do_action( 'wpbc_import_google_calendar' $params, $action_result ); // where $params is array and $action_result array and have $action_result['after_action_result'], which contains a boolean value of the result of an operation.
694 do_action( 'wpbc_export_csv' $params, $action_result ); // where $params is array and $action_result array and have $action_result['after_action_result'], which contains a boolean value of the result of an operation.
695
696 */
697
698 /**
699 * Hook for adding new payment status(es) in Booking Listing page:
700 *
701 * apply_filters ('wpbc_filter_payment_status_list' , $payment_status_titles );
702 *
703 * Use this code in your functions.php file in your theme to add your own Payment status for Booking Listing page:
704 *
705 * function my_wpbc_filter_payment_status_list( $payment_status_titles ) {
706 * $payment_status_titles[ 'invoice' ] = ' Invoice Payment';
707 * return $payment_status_titles;
708 * }
709 * add_filter( 'wpbc_filter_payment_status_list', 'my_wpbc_filter_payment_status_list', 10, 1 );
710 */
711
712 /**
713 * Hook that executes upon the deletion of booking resources: do_action( 'wpbc_deleted_booking_resources', $bulk_action_arr_id ); // (10.0.0.35)
714 *
715 * Example:
716 * function my_func__on_resource_delete( $resources_id_str ){
717 * $resources_id_arr = explode( ',', $resources_id_str );
718 * // Do something ...
719 * }
720 * add_action( 'wpbc_deleted_booking_resources', 'my_func__on_resource_delete' );
721 */