Set None as Default to Delivery Time and Uncheck Default Order Type

February 15, 2021

Uncategorized
add_action("wp_footer", function()

{
	global $woocommerce;
	if(is_checkout())
	{



		?>
		<script>
			jQuery(document).ready(function()

			{


				jQuery('.woofood_order_type input').removeAttr('checked');
				jQuery('#woofood_time_to_deliver').prepend('<option value="0">Please select a time</option>');
				jQuery('#woofood_time_to_pickup').prepend('<option value="0">Please select a time</option>');


			});
		</script>

		<?php
	}	   
});

add_action("woocommerce_checkout_process", "wpslash_check_time_order_checked", 99, 0);

function wpslash_check_time_order_checked()

{

	if(!isset($_POST["woofood_order_type"]))
	{
			wc_clear_notices();

		wc_add_notice("Please select Delivery or Pickup", "error");
	}

	$order_type = isset($_POST["woofood_order_type"]) ? $_POST["woofood_order_type"] : "";



	if( (isset($_POST["woofood_time_to_deliver"]) || $_POST["woofood_time_to_deliver"] ="0"  ) && $order_type =="delivery")
	{
					wc_clear_notices();

		wc_add_notice("Please select a time for delivery", "error");
	}
	if( (isset($_POST["woofood_time_to_pickup"]) || $_POST["woofood_time_to_pickup"] ="0") && $order_type =="pickup")
	{
					wc_clear_notices();

		wc_add_notice("Please select a time to pickup", "error");
	}




}