I am using xdsoft date time picker at woo-commerce checkout and need to add an extra fee if a user selects the same day or tomorrow on the date time picker. I am not sure how to go with this and would appreciate it if someone can help me with this.
Below is the code I am using currently and it is working fine for the situation.
function date_time_picker( $checkout ) {
woocommerce_form_field( 'delivery_date', array(
'type' => 'text',
'class' => array('form-row-wide'),
'id' => 'datepicker',
'required' => true,
'label' => __('Select Delivery Date'),
'placeholder' => __('Click to select date'),
));
}
add_action( 'woocommerce_after_order_notes', 'date_time_picker' );
function validate_new_checkout_fields() {
if ( isset( $_POST['delivery_date'] ) && empty( $_POST['delivery_date'] ) ) wc_add_notice( __( 'Please select the Delivery Date' ), 'error' );
}
add_action( 'woocommerce_checkout_process', 'validate_new_checkout_fields' );
function enable_datepicker() {
?>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.full.min.js"></script>
<?php
}
add_action( 'woocommerce_after_checkout_form', 'enable_datepicker', 10 );
function load_calendar_dates( $available_gateways ) {
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
jQuery.datetimepicker.setLocale('en');
var currentDate = new Date();
var minutes = currentDate.getMinutes();
var m = (Math.ceil(minutes/30) * 30) % 60;
currentDate.setMinutes(m);
jQuery('#datepicker').datetimepicker({
beforeShowDay: $.datepicker.noWeekends,
format: 'Y/m/d H:i:s',
minDate: 0,
minTime: '8:00',
step: "30",
allowTimes:[
'09:00', '09:30', '10:00', '10:30', '11:00', '11:30', '12:00', '12:30',
'13:00', '13:30', '14:00', '14:30', '15:00', '15:30', '16:00', '16:30', '17:00'
]
});
});
</script>
<?php
}
add_action( 'woocommerce_after_checkout_form', 'load_calendar_dates', 20 );