我想在 WooCommerce 的后端(在订单概览中)显示原产国运输。怎么做

i want to show origin country shipping in the backend of WooCommerce (in Orders overview). How to do it

我在 wordpress 中使用 WooCommerce 并使用 ups 运输。我有 2 家商店,地址不同。我想在后台显示原产国运费。

#-----------------------------------------------------------------#
# Test show distro in admin order page
#-----------------------------------------------------------------# 
//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;
}
// How can i do it here???????
add_action( 'manage_shop_order_posts_custom_column', 'MY_COLUMNS_VALUES_FUNCTION', 2 );
function MY_COLUMNS_VALUES_FUNCTION($column){
    global $post;
    $data = get_post_meta( $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 == 'MY_COLUMN_ID_1' ) {    
        echo (isset($data['MY_COLUMN_1_POST_META_ID']) ? $data['MY_COLUMN_1_POST_META_ID'] : '');
    }

    //stop editing
}
// make column can sort
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 );
}

有人查看我的代码并告诉我我应该怎么做吗? This is example

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' ) {

    echo (isset($the_order->shipping_postcode) ? $the_order->shipping_postcode : '');
}
//stop editing
}

感谢 1way 的回答。