The problem with date formats is that everyone has their own preference.
Admins and inventory managers often have different requirements for date formats. This often happens in WooCommerce stores, where stakeholders have different requirements to customize the date format.
In this short tutorial, I will show how to customize the WooCommerce date format without much effort. Note that the code for these functions should be added to the functions.php file located in the theme folder.
Default Date Format in WooCommerce
Fortunately, changing the default date format in WooCommerce simply uses a filter and a function.
To change the date and time format in WooCommerce, go to the “Settings” menu in the WooCommerce dashboard and click on the “General” tab. Scroll down to the “Date Format” and “Time Format” settings and choose the desired format from the drop-down menu.
From launching to customizing your WooCommerce stores, Cloudways is at your service.
Whether you’re a beginner or an expert, Cloudways Platform is based on UI, where you can create and customize your online store in a few seconds.
Add Custom Date Format in WooCommerce
Customizing the date format in WooCommerce is a simple process that can help to improve the user experience for customers and better align the store with your branding and style.
The following code alters the WooCommerce date format to Y/M/D:
add_filter('woocommerce_admin_order_date_format', 'cw_custom_post_date_column_time'); function cw_custom_post_date_column_time($h_time, $post) { return get_the_time(__('Y/m/d G:i', 'woocommerce'), $post); }
If you want to change the format to D/M/Y, just modify the last line of the function to:
 return get_the_time(__('d/m/Y G:i', 'woocommerce'), $post);
Alternate Method for Custom Date Format
The following code option presents an alternate solution for the problem:
add_filter( 'post_date_column_time' ,'woo_custom_post_date_column_time_withDate' ); function woo_custom_post_date_column_time_withDate( $post ) { $t_time = get_the_time( __( 'd/m/Y g:i:s A', 'woocommerce' ), $post ); return $t_time; } add_filter( 'post_date_column_time' , 'woo_custom_post_date_column_time' ); function woo_custom_post_date_column_time( $post ) { $h_time = get_the_time( __( 'd/m/Y', 'woocommerce' ), $post ); return $h_time; }
Summary
By customizing the date format in WooCommerce, you can easily control how dates and times are displayed throughout your online store. It is important to carefully consider the date format you choose, as it can impact how easily customers understand and interpret dates and times displayed on your WooCommerce store.
Owais Alam
is the WordPress Community Manager at Cloudways - A Managed WooCommerce Hosting Platform and a seasoned PHP developer. He loves to develop all sorts of websites on WordPress and is in love with WooCommerce in particular. You can email him at [email protected]