WooCommerce Delivery Date Plugin

This plugin introduces a mandatory delivery date field at the WooCommerce checkout process. It saves the date selected by the customer and displays it on the admin order page, ensuring the delivery date is clearly communicated to store management.

<?php /* Plugin Name: WooCommerce Delivery Date Plugin URI: Description: This plugin adds a delivery date field to WooCommerce checkout process and shows it on the admin order page. Author: CodeWP Assistant Author URI: Version: 1.0 License: GPLv2 or later Text Domain: codewp */ // Add delivery date field to the checkout add_action("woocommerce_after_order_notes", "cwpai_add_delivery_date_field"); function cwpai_add_delivery_date_field($checkout) { echo '<div id="cwpai_delivery_date_field"><h2>' . __("Delivery Date") . "</h2>"; woocommerce_form_field( "cwpai_delivery_date", [ "type" => "date", "class" => ["cwpai-field-class form-row-wide"], "required" => true, // this field is mandatory ], $checkout->get_value("cwpai_delivery_date") ); echo "</div>"; } // Save delivery date to the order meta add_action( "woocommerce_checkout_update_order_meta", "cwpai_save_delivery_date_to_order_meta" ); function cwpai_save_delivery_date_to_order_meta($order_id) { if (!empty($_POST["cwpai_delivery_date"])) { update_post_meta( $order_id, "cwpai_delivery_date", sanitize_text_field($_POST["cwpai_delivery_date"]) ); } } // Display delivery date in the custom column add_action('woocommerce_admin_order_data_after_shipping_address', 'cwpai_my_orders_delivery_date_column'); function cwpai_my_orders_delivery_date_column($order) { $delivery_date = "<strong>Delivery Date:</strong><br>" . get_post_meta($order->get_id(), 'cwpai_delivery_date', true); // Get custom order meta echo !empty($delivery_date) ? $delivery_date : 'N/A'; }

Frequently Asked Questions

The code adds a delivery date selection field to the WooCommerce checkout page and saves the chosen date in the order metadata.