majeedraza

WooCommerce - Show full date in order list

Apr 11th, 2021 (edited)
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.99 KB | None | 0 0
  1. <?php
  2. // WooCommerce - Show full date in order list
  3. add_filter( 'manage_shop_order_posts_columns', 'custom_shop_order_posts_columns', 99 );
  4. function custom_shop_order_posts_columns( $columns ) {
  5.   $new_columns = array();
  6.   foreach( $columns as $key => $name ) {
  7.     if( 'order_date' == $key ) {
  8.       $new_columns['custom_order_date'] = 'Date';
  9.     } else {
  10.       $new_columns[$key] = $name;
  11.     }    
  12.   }
  13.   return $new_columns;
  14. }
  15.  
  16. add_action( 'manage_shop_order_posts_custom_column' , 'show_custom_columns', 10, 2 );
  17. function show_custom_columns( $column_name, $post_id ) {
  18.   if( 'custom_order_date' == $column_name ) {
  19.     $order = wc_get_order( $post_id );
  20.     if( ! $order ) {
  21.       return;
  22.     }
  23.     $order_timestamp = $order->get_date_created() ? $order->get_date_created()->getTimestamp() : '';
  24.     if ( ! $order_timestamp ) {
  25.       print '&ndash;';
  26.       return;
  27.     }
  28.     print date( get_option( 'date_format' ).' '.get_option( 'time_format' ), $order_timestamp );
  29.   }
  30. }
Add Comment
Please, Sign In to add comment