Skip to content

Instantly share code, notes, and snippets.

@rafiahmedd
Last active October 22, 2022 00:41
Show Gist options
  • Save rafiahmedd/da73856c7c9e326ad71d3052746f5f95 to your computer and use it in GitHub Desktop.
Save rafiahmedd/da73856c7c9e326ad71d3052746f5f95 to your computer and use it in GitHub Desktop.
FF Booking system
<?php
add_action( 'wp_footer', 'booking', 999999999);
function booking(){
$formId = 43; //Target a specific form here by id
$fields = wpFluent()->table('fluentform_submissions')
->where('form_id', $formId)
->get();
$toDisable = [];
foreach ($fields as $key=>$value) {
$response = json_decode($value->response);
$toDisable[]= $response->datetime;
}
?>
<script type="text/javascript">
jQuery(document).ready(function($){
function initPicker() {
var toDisable = [];
<?php foreach ($toDisable as $date){?>
toDisable.push("<?php echo $date?>");
<?php }?>
if(typeof flatpickr == 'undefined') {
return;
}
flatpickr.localize(window.fluentFormVars.date_i18n);
var config = {"dateFormat":"d\/m\/Y","enableTime":false,"noCalendar":false,"disableMobile":true,"time_24hr":false};
try {
var customConfig = {
disable: toDisable,
};
} catch (e) {
var customConfig = {};
}
var config = $.extend({}, config, customConfig);
if (!config.locale) {
config.locale = 'default';
}
/**
* jQuery('#ff_<?php echo $formId?>_datetime')
* date field id, so please use the right field id here
* it will return jQuery('#ff_43_datetime')
*/
if(jQuery('#ff_<?php echo $formId?>_datetime').length) {
flatpickr('#ff_<?php echo $formId?>_datetime', config);
}
}
initPicker();
$(document).on('reInitExtras', '.ff_form_instance_<?php echo $formId?>_1', function () {
initPicker();
});
})
</script>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment