Reputation: 93
In WooCommerce I was using the code below to alter the admin orders view formatting of the order date column:
// Woocommerce show time on order
add_filter('post_date_column_time', 'custom_post_date_column_time', 10, 2);
function custom_post_date_column_time($h_time, $post)
{
return get_the_time(__('Y/m/d g:i:s A', 'woocommerce'), $post);
}
Since WooCommerce 3.0+ it has just stopped working.
Any ideas?
Thanks
Upvotes: 2
Views: 3764
Reputation: 113
From https://wordpress.org/support/topic/show-time-on-order-backend-broken-since-woo-3/ working under WooCommerce Version 6.7.0
add_filter('woocommerce_admin_order_date_format', 'custom_post_date_column_time');
function custom_post_date_column_time($format)
{
return __('Y-m-d h:i', 'woocommerce');
}
Upvotes: 1
Reputation: 93
THE RIGHT ANSWER:
Please see the official WooCommerce answer thread
For ease of reference for others, the new filter is due to be released in WooCommerce 3.0.2.
Patch can be manually applied from https://github.com/woocommerce/woocommerce/pull/14253
It works with a custom function hooked in woocommerce_admin_order_date_format
new filter hook:
// Woocommerce show time on order
add_filter('woocommerce_admin_order_date_format', 'custom_post_date_column_time');
function custom_post_date_column_time($h_time, $post)
{
return get_the_time(__('Y/m/d G:i', 'woocommerce'), $post);
}
Upvotes: 1
Reputation: 254353
In WC core code class-wc-admin-post-types.php
if you look at render_shop_order_columns()
function, things have changed since WooCommerce version 3.0+, as it uses WC_Abstract_Order
get_date_created()
method instead of WordPress function get_the_time()
.
So that is why the hook that you are using is not working anymore.
Here is an extract of the source code in WooCommerce version 3.0+:
case 'order_date' :
printf( '<time datetime="%s">%s</time>', esc_attr( $the_order->get_date_created()->date( 'c' ) ), esc_html( $the_order->get_date_created()->date_i18n( __( 'Y-m-d', 'woocommerce' ) ) ) );
break;
And Here the same source code extract in WooCommerce version 2.6.x:
case 'order_date' :
if ( '0000-00-00 00:00:00' == $post->post_date ) {
$t_time = $h_time = __( 'Unpublished', 'woocommerce' );
} else {
$t_time = get_the_time( __( 'Y/m/d g:i:s A', 'woocommerce' ), $post );
$h_time = get_the_time( __( 'Y/m/d', 'woocommerce' ), $post );
}
echo '<abbr title="' . esc_attr( $t_time ) . '">' . esc_html( apply_filters( 'post_date_column_time', $h_time, $post ) ) . '</abbr>';
break;
Now if you look to the source code of
get_date_created()
it's using the newWC_Data
getter methodget_prop()
. In the source code ofget_prop()
you have this new filter hook possibility to explore:$value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
Upvotes: 4