Change The Date Or Time Slot Format On An Order
The code in this article requires WooCommerce Delivery Slots v1.7.7+
It’s possible to change or modify the date and time slot content which is displayed in the admin or to the customer after placing an order.
You can add any of the code given to your child theme’s functions.php
file, or using the Code Snippets plugin.
Change the Delivery Date display
To change the date display, we will use the iconic_wds_date_display
filter.
We can use PHP’s date() function to reformat the date like so:
/**
* Change date display.
*
* @param string $date
* @param array $date_time
*
* @return string
*/
function iconic_change_date_display( $date, $date_time ) {
if ( is_admin() ) {
return $date;
}
if ( empty( $date_time['timestamp'] ) ) {
return $date;
}
return date( 'l jS F, Y', $date_time['timestamp'] );
}
add_filter( 'iconic_wds_date_display', 'iconic_change_date_display', 10, 2 );
Firstly, we’re checking if we’re on an admin page. if we are, we return the date in its normal format. Then we check if the timestamp parameter is set. If it isn’t, we again return the date as normal. Finally, we use PHP’s date()
function to change the format of our date.
The date/time display will now look like this:
Change the Time Slot display
To change the date display, we will use the iconic_wds_time_display
filter.
/**
* Change time display.
*
* @param string $time
* @param array $date_time
*
* @return string
*/
function iconic_change_time_display( $time, $date_time ) {
return $time;
}
add_filter( 'iconic_wds_time_display', 'iconic_change_time_display', 10, 2 );
You can modify the returned $time
string however you see fit.
WooCommerce Delivery Slots
Choose a delivery date and time for each order. Add a limit to the number of allowed reservations, restrict time slots to specific delivery methods, and so much more.
Was this helpful?
Please let us know if this article was useful. It is the best way to ensure our documentation is as helpful as possible.