在WC核心代码中class-wc-admin-post-types.php
如果你看render_shop_order_columns()
功能,自 WooCommerce 版本 3.0+ 以来,情况发生了变化,因为它使用WC_Abstract_Order
get_date_created() https://docs.woocommerce.com/wc-apidocs/source-class-WC_Abstract_Order.html#254-262方法而不是 WordPress 函数get_the_time() https://codex.wordpress.org/Function_Reference/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;
现在如果你查看源代码get_date_created() https://docs.woocommerce.com/wc-apidocs/source-class-WC_Abstract_Order.html#254-262它正在使用新的WC_Data
获取方法get_prop()
。在源代码中get_prop() https://docs.woocommerce.com/wc-apidocs/source-class-WC_Data.html#600-623您可以探索这个新的过滤器挂钩可能性:
$value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );