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 give 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 jckwds_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( 'jckwds_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  jckwds_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( 'jckwds_time_display', 'iconic_change_time_display', 10, 2 );

You can modify the returned $time string however you see fit.

Still need help? Contact Us Contact Us