Created
August 26, 2021 20:18
-
-
Save kartikparmar/da4e8e94d12d40cf66d4564c5f7a2be6 to your computer and use it in GitHub Desktop.
Default options of Booking when creating new product
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Enabling the required option for new product. | |
| function bkap_enable_option_for_new_product( $booking_checked, $duplicate_of, $booking_settings ) { | |
| if ( '' === $booking_settings ) { // enable booking option for new product. | |
| $booking_checked = 'checked'; | |
| } | |
| return $booking_checked; | |
| } | |
| add_filter( 'bkap_enable_booking', 'bkap_enable_option_for_new_product', 10, 3 ); | |
| add_filter( 'bkap_inline_calendar_option', 'bkap_enable_option_for_new_product', 10, 3 ); | |
| // Setting default Booking type to Duration Based Time | |
| function bkap_default_booking_type_for_new_product( $booking_type, $duplicate_of, $booking_settings ){ | |
| if ( '' === $booking_settings ) { // enable booking option for new product. | |
| $booking_type = 'duration_time'; | |
| } | |
| return $booking_type; | |
| } | |
| add_filter( 'bkap_booking_type', 'bkap_default_booking_type_for_new_product', 10, 3 ); | |
| // Setting Minimum Duration to 4. | |
| function bkap_minimum_duration( $min, $product_id, $booking_settings ) { | |
| if ( '' === $booking_settings ) { // enable booking option for new product. | |
| $min = 4; | |
| } | |
| return $min; | |
| } | |
| add_filter( 'bkap_minimum_duration', 'bkap_minimum_duration', 10, 3 ); | |
| // inline script via wp_print_scripts. | |
| function bkap_print_scripts() { | |
| if ( 'product' == get_post_type() ) { | |
| ?> | |
| <script> | |
| jQuery( document ).ready( function () { | |
| if( jQuery('#bkap-booking-type' ).length > 0 ) { | |
| jQuery('#bkap-booking-type' ).trigger( 'change' ); | |
| } | |
| }); | |
| </script> | |
| <?php | |
| } | |
| } | |
| add_action( 'wp_print_scripts', 'bkap_print_scripts' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment