duanchuaiwan0063 2016-10-15 10:53
浏览 29
已采纳

在管理员 - > Woocommerce - >订单的“订单”列表中显示货运邮政编码

How can I display the shipping zip code associated to order in the “Orders” list view? Is there a hook that is available to include the shipping as an item in the individual order row? Thank you.

//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 );
}
  • 写回答

1条回答 默认 最新

  • dqxhit3376 2016-10-15 17:03
    关注

    I tested this and that work on the latest woocommerce version. The way to get order data changed since the link i sent you. So test this :

    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
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行