Skip to content

Instantly share code, notes, and snippets.

@MjHead
Created December 3, 2024 20:49
Show Gist options
  • Save MjHead/955720baa5594a63136e508252cbcf30 to your computer and use it in GitHub Desktop.
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
<?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