在woocommerce 3.3的管理员订单列表中添加列 [英] Add columns in admin order list on woocommerce 3.3

查看:110
本文介绍了在woocommerce 3.3的管理员订单列表中添加列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关: 在WooCommerce后端的管理订单列表中添加列

是否可以在管理订单列表中仅添加一个新列.对于此列my-column1的内容,我希望有2个自定义字段,例如:

Is it possible to add only one new column in admin Order list instead. For the content of this column my-column1 I will like to have 2 custom fields like:

$my_var_one = get_post_meta( $post_id, '_the_meta_key1', true );

$my_var_two = get_post_meta( $post_id, '_the_meta_key2', true );

要完成此操作,是否可以将新列放在order_number之后?

To finish is it possible to position this new column after the order_number?

感谢您的帮助.

推荐答案

已更新-可以通过以下方式完成:

Updated - It can be done this way:

// ADDING 1 NEW COLUMNS WITH THEIR TITLES
add_filter( 'manage_edit-shop_order_columns', 'custom_shop_order_column',11);
function custom_shop_order_column($columns)
{
    $reordered_columns = array();

    foreach( $columns as $key => $column){
        $reordered_columns[$key] = $column;
        if( $key ==  'order_number' ){
            $reordered_columns['my-column1'] = __( 'Title1','theme_slug');
        }
    }
    return $reordered_columns;
}

// Adding the data for the additional column (example)
add_action( 'manage_shop_order_posts_custom_column' , 'custom_orders_list_column_content', 10, 2 );
function custom_orders_list_column_content( $column, $post_id )
{
    if( 'my-column1' == $column )
    {
        // Get custom post meta data 1
        $my_var_one = get_post_meta( $post_id, '_the_meta_key1', true );
        if(!empty($my_var_one))
            echo $my_var_one;

        // Get custom post meta data 2
        $my_var_two = get_post_meta( $post_id, '_the_meta_key2', true );
        if(!empty($my_var_two))
            echo $my_var_two;

        // Testing (to be removed) - Empty value case
        if( empty($my_var_one) && empty($my_var_two) )
            echo '<small>(<em>no value</em>)</small>';
    }
}

其他功能保持不变...

The other function stays unchanged…

代码进入您的活动子主题(或活动主题)的function.php文件中.经过测试并可以正常工作.

Code goes in function.php file of your active child theme (or active theme). Tested and works.

这篇关于在woocommerce 3.3的管理员订单列表中添加列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆