Aleš Sýkora wrote

Change required fields by current time in Iconic Delivery Slots

21. 1. 2021 in

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!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

More from category
Aleš Sýkora wrote
Display list of WooCommerce categories
19. 2. 2021 in
If you need to display list of all WooCommerce categories without products, you can use my code. It will display all categories with link to their archive page. It will also display category image, name of course and count of products inside the category. It is all wrapped in HTML with OxyNinja framework applied. So […]
Read More
Aleš Sýkora wrote
Best practise for jQuery in Toolset
3. 7. 2019 in
Let me explain best practices for using jQuery inside a View, Form or Content Template's JS panel.
Read More
Aleš Sýkora wrote
Woocommerce AJAX add to cart button in Oxygen repeater
5. 5. 2020 in ,
If you want to style custom repeater for woocommerec product categories in Oxygen builder and use the AJAX buttons in it feel free to use them with shortcode [add_to_cart id=""] or just copy the button html with class="add_to_cart_button ajax_add_to_cart"
Read More
magnifiercross linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram