gpt4 book ai didi

php - WooCommerce 3.0+ 更改管理员订单日期列格式

转载 作者:行者123 更新时间:2023-12-02 03:57:27 25 4
gpt4 key购买 nike

在 WooCommerce 中,我使用下面的代码来更改订单日期列的管理订单 View 格式:

// 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()方法而不是 WordPress 函数 get_the_time() .

这就是您使用的 Hook 不再起作用的原因。

这是 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 );

关于php - WooCommerce 3.0+ 更改管理员订单日期列格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43331509/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com