在 Admin -> Woocommerce -> Orders 的 "Orders" 列表中显示运输邮政编码
Displaying shipping zip code in the "Orders" list on Admin -> Woocommerce -> Orders
如何在“订单”列表视图中显示与订单关联的发货邮政编码?是否有一个挂钩可用于将运费作为一个项目包含在单个订单行中?
谢谢。
//add a column
add_filter( 'manage_edit-shop_order_columns', 'MY_COLUMNS_FUNCTION' );
function MY_COLUMNS_FUNCTION($columns){
$new_columns = (is_array($columns)) ? $columns : array();
unset( $new_columns['order_actions'] );
//edit this for you column(s)
//all of your columns will be added before the actions column
$new_columns['MY_COLUMN_ID_1'] = 'Distro test';
//stop editing
$new_columns['order_actions'] = $columns['order_actions'];
return $new_columns;
}
// add data to column
add_action( 'manage_shop_order_posts_custom_column', 'MY_COLUMNS_VALUES_FUNCTION', 2 );
function MY_COLUMNS_VALUES_FUNCTION($column){
// ***WHAT MUST I DO HERE!!!!!!!!!!!!!!!!***
//stop editing
}
// sort column
add_filter( "manage_edit-shop_order_sortable_columns", 'MY_COLUMNS_SORT_FUNCTION' );
function MY_COLUMNS_SORT_FUNCTION( $columns ) {
$custom = array(
//start editing
'MY_COLUMN_ID_1' => 'MY_COLUMN_1_POST_META_ID'
//stop editing
);
return wp_parse_args( $custom, $columns );
}
我在最新的 woocommerce 版本上测试了这个和那个。自从我发送给您的 link 以来,获取订单数据的方式发生了变化。所以测试这个:
add_filter( 'manage_edit-shop_order_columns', 'MY_COLUMNS_FUNCTION' );
function MY_COLUMNS_FUNCTION($columns){
$new_columns = (is_array($columns)) ? $columns : array();
unset( $new_columns['order_actions'] );
//edit this for you column(s)
//all of your columns will be added before the actions column
$new_columns['zip_code'] = 'Zip Code';
//stop editing
$new_columns['order_actions'] = $columns['order_actions'];
return $new_columns;
}
add_action( 'manage_shop_order_posts_custom_column', 'MY_COLUMNS_VALUES_FUNCTION',10, 2 );
function MY_COLUMNS_VALUES_FUNCTION($column){
global $post, $the_order;
if ( empty( $the_order ) || $the_order->id != $post->ID ) {
$the_order = wc_get_order( $post->ID );
}
//start editing, I was saving my fields for the orders as custom post meta
//if you did the same, follow this code
if ( $column == 'zip_code' ) {
if(isset($the_order->shipping_postcode)):
$zip_code = $the_order->shipping_postcode;
if($zip_code == 'california store zip code'):
echo 'California';
elseif($zip_code == 'other store zip code'):
echo 'Other store location';
else:
echo $zip_code;
endif;
endif;
}
//stop editing
}
如何在“订单”列表视图中显示与订单关联的发货邮政编码?是否有一个挂钩可用于将运费作为一个项目包含在单个订单行中? 谢谢。
//add a column
add_filter( 'manage_edit-shop_order_columns', 'MY_COLUMNS_FUNCTION' );
function MY_COLUMNS_FUNCTION($columns){
$new_columns = (is_array($columns)) ? $columns : array();
unset( $new_columns['order_actions'] );
//edit this for you column(s)
//all of your columns will be added before the actions column
$new_columns['MY_COLUMN_ID_1'] = 'Distro test';
//stop editing
$new_columns['order_actions'] = $columns['order_actions'];
return $new_columns;
}
// add data to column
add_action( 'manage_shop_order_posts_custom_column', 'MY_COLUMNS_VALUES_FUNCTION', 2 );
function MY_COLUMNS_VALUES_FUNCTION($column){
// ***WHAT MUST I DO HERE!!!!!!!!!!!!!!!!***
//stop editing
}
// sort column
add_filter( "manage_edit-shop_order_sortable_columns", 'MY_COLUMNS_SORT_FUNCTION' );
function MY_COLUMNS_SORT_FUNCTION( $columns ) {
$custom = array(
//start editing
'MY_COLUMN_ID_1' => 'MY_COLUMN_1_POST_META_ID'
//stop editing
);
return wp_parse_args( $custom, $columns );
}
我在最新的 woocommerce 版本上测试了这个和那个。自从我发送给您的 link 以来,获取订单数据的方式发生了变化。所以测试这个:
add_filter( 'manage_edit-shop_order_columns', 'MY_COLUMNS_FUNCTION' );
function MY_COLUMNS_FUNCTION($columns){
$new_columns = (is_array($columns)) ? $columns : array();
unset( $new_columns['order_actions'] );
//edit this for you column(s)
//all of your columns will be added before the actions column
$new_columns['zip_code'] = 'Zip Code';
//stop editing
$new_columns['order_actions'] = $columns['order_actions'];
return $new_columns;
}
add_action( 'manage_shop_order_posts_custom_column', 'MY_COLUMNS_VALUES_FUNCTION',10, 2 );
function MY_COLUMNS_VALUES_FUNCTION($column){
global $post, $the_order;
if ( empty( $the_order ) || $the_order->id != $post->ID ) {
$the_order = wc_get_order( $post->ID );
}
//start editing, I was saving my fields for the orders as custom post meta
//if you did the same, follow this code
if ( $column == 'zip_code' ) {
if(isset($the_order->shipping_postcode)):
$zip_code = $the_order->shipping_postcode;
if($zip_code == 'california store zip code'):
echo 'California';
elseif($zip_code == 'other store zip code'):
echo 'Other store location';
else:
echo $zip_code;
endif;
endif;
}
//stop editing
}