WooCommerce 3.0+ 更改管理员订单日期列格式
WooCommerce 3.0+ change admin order date column format
在 WooCommerce 中,我使用以下代码更改订单日期列的管理订单视图格式:
// 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);
}
从 WooCommerce 3.0+ 开始它就停止工作了。
有什么想法吗?
谢谢
在 WC 核心代码 class-wc-admin-post-types.php
中,如果您查看 render_shop_order_columns()
函数,自 WooCommerce 3.0+ 版本以来情况发生了变化,因为它使用 WC_Abstract_Order
get_date_created()
method instead of WordPress function get_the_time()
.
这就是您使用的挂钩不再起作用的原因。
这是 WooCommerce 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;
这里是 WooCommerce 版本 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 new WC_Data
getter method get_prop()
. In the source code of get_prop()
you have this new filter hook possibility to explore:
$value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
正确答案:
For ease of reference for others, the new filter is due to be released in WooCommerce 3.0.2.
可以从 https://github.com/woocommerce/woocommerce/pull/14253
手动应用补丁
它与挂钩在 woocommerce_admin_order_date_format
新过滤器挂钩中的自定义函数一起工作:
// 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);
}
在 WooCommerce 中,我使用以下代码更改订单日期列的管理订单视图格式:
// 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);
}
从 WooCommerce 3.0+ 开始它就停止工作了。
有什么想法吗?
谢谢
在 WC 核心代码 class-wc-admin-post-types.php
中,如果您查看 render_shop_order_columns()
函数,自 WooCommerce 3.0+ 版本以来情况发生了变化,因为它使用 WC_Abstract_Order
get_date_created()
method instead of WordPress function get_the_time()
.
这就是您使用的挂钩不再起作用的原因。
这是 WooCommerce 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;
这里是 WooCommerce 版本 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 );
正确答案:
For ease of reference for others, the new filter is due to be released in WooCommerce 3.0.2.
可以从 https://github.com/woocommerce/woocommerce/pull/14253
手动应用补丁它与挂钩在 woocommerce_admin_order_date_format
新过滤器挂钩中的自定义函数一起工作:
// 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);
}