尝试将以下代码添加到你的functions.php
文件中
add_filter( 'manage_edit-shop_order_columns', 'shop_order_columns' );
function shop_order_columns( $columns ){
$new_columns = (is_array($columns)) ? $columns : array();
$new_columns['phone'] = 'Phone';
return $new_columns;
}
add_action( 'manage_shop_order_posts_custom_column', 'shop_order_posts_custom_column' );
function shop_order_posts_custom_column( $column ){
global $post, $the_order;
if ( empty( $the_order ) || $the_order->get_id() != $post->ID ) {
$the_order = wc_get_order( $post->ID );
}
$billing_address = $the_order->get_address();
if ( $column == 'phone' ) {
echo ( isset( $billing_address['phone'] ) ? $billing_address['phone'] : '');
}
}
定位问题??..
尝试使用以下内容来调用第一个函数
function shop_order_columns($columns){
$columns = (is_array($columns)) ? $columns : array();
$phone = array( 'phone' => 'Phone' );
$position = 5;
$new_columns = array_slice( $columns, 0, $position, true ) + $phone;
return array_merge( $new_columns, $columns );
}
适用于 WooCommerce 3 更新。
manage_shop_order_posts_custom_column
动作,并通过检查列名称来更改列数据。switch( $column ) {
case 'shipping_address' :
echo 'sample data';
break;
}