WORDPRESS - Oxygen - toolset

Change required fields by current time in Iconic Delivery Slots

Author: Aleš Sýkora, 21. 1. 2021

If you need to set the fields required in some times, you need to use custom function for that. Why is it needed? For example ASAP delivery is not possible to cutoff in the morning. You can set cutoff time in the evening. but next day, it is avaible immediately after midnight.

So I created my custom radio buttons which says - ASAP delivery / Planned delivery and I disabled ASAP delivery in Iconic. But when I am not operating in restaurant, I am hiding the ASAP delivery and setting up the planned delivery and I need it to be required.

That's the problem I am solving with this snippet. I want the Iconic delivery date and time required between 20:30 till 11:00.

/**
 * Modify required parameter for date field in the front end.
 *
 * @param array $field.
 *
 * @return array
 */
function iconic_modify_checkout_fields_data( $field ) {
	if ( 'Delivery Date' !== $field['field_args']['label'] && 'Time Slot' !== $field['field_args']['label'] ) {
		return $field;
	}

	$current_time = current_time( 'H:i' ); 
	if ( $current_time < '11:00' || $current_time > '20:30' ) {
		$field['field_args']['required'] = true;
	}

	return $field;
}

add_filter( 'iconic_wds_checkout_field_data', 'iconic_modify_checkout_fields_data' );

Attention! If you already changed your delivery slots labels, you need to change them in this snippet too!