Created
December 3, 2024 20:49
-
-
Save MjHead/955720baa5594a63136e508252cbcf30 to your computer and use it in GitHub Desktop.
JetBooking. Allow booking only with fixed date range based on the post meta
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 | |
add_action( 'wp_footer', function() { | |
$days_to_book = get_post_meta( get_the_ID(), 'booking_duration' ); | |
if ( ! $days_to_book ) { | |
$days_to_book = 1; | |
} | |
$days_to_book = $days_to_book - 1; | |
?> | |
<script> | |
var jetBookingDaysNum = <?php echo $days_to_book; ?>; | |
jQuery( document ).on( "jet-booking/init-field", ( $event, $field ) => { | |
$field.bind( "datepicker-first-date-selected", ( event, obj ) => { | |
$field.data( "dateRangePicker" ).setEnd( moment( obj.date1 ).add( jetBookingDaysNum, "d" ).format( "YYYY-MM-DD" ) ); | |
} ); | |
} ); | |
</script> | |
<?php | |
}, 99 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment