Skip to content

Instantly share code, notes, and snippets.

@kartikparmar
Created August 26, 2021 20:18
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kartikparmar/da4e8e94d12d40cf66d4564c5f7a2be6 to your computer and use it in GitHub Desktop.
Default options of Booking when creating new product
<?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