Skip to content

Instantly share code, notes, and snippets.

@Pibolo Pibolo/w-filter-select.php Secret
Created Feb 14, 2020

Embed
What would you like to do?
add_action('wp_ajax_updater_slots', 'w_update_slots');
add_action('wp_ajax_nopriv_updater_slots', 'w_update_slots');
function w_update_slots()
{a
$hours = array(
'9:30' => array('09:30', true),
'11:30' => array('11:30', true),
'13:30' => array('13:30', true),
'15:30' => array('15:30', true),
);
$day = $_GET['date'];
$unavailable = get_current_slots_for_a_day($day);
foreach ($unavailable as $un) {
$hours[$un][1] = false;
}
$html = array_map('w_format_option', $hours);
wp_send_json(array(
'values' => $hours,
'html' => implode(PHP_EOL, $html),
));
exit;
}
/**
* Ajax request to get available time slots
*/
add_action('wp_footer', 'test_update', 100);
function test_update()
{
?>
<script>
jQuery(document).ready(function($){
$(document).on('change', '.need-dynamic-date .wpforms-field-date-time-date',function() {
$.ajax({
url:'<?php echo admin_url('admin-ajax.php'); ?>',
data:{
action:'updater_slots',
date:$('.need-dynamic-date .wpforms-field-date-time-date').val(),
},
method:'GET',
success:function(data){
$('.need-dynamic-time select').html( data.html );
$("#wpforms-240-field_60 option[value='17:30']").prop("disabled",true).append('réservé');
}
});
});
});
</script>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.