복붙노트

[WORDPRESS] WooCommerce 주문 페이지 추가 고객 역할의 사용자 정의 열

WORDPRESS

WooCommerce 주문 페이지 추가 고객 역할의 사용자 정의 열

해결법


  1. 1.테마의 functions.php 코드 아래에 추가

    테마의 functions.php 코드 아래에 추가

    add_filter('manage_edit-shop_order_columns', 'add_column_heading', 20, 1);
    
    function add_column_heading($array) {
    
    
        $res = array_slice($array, 0, 2, true) +
                array("customer_role" => "Customer Role") +
                array_slice($array, 2, count($array) - 1, true);
    
        return $res;
    }
    
    add_action('manage_posts_custom_column', 'add_column_data', 20, 2);
    
    function add_column_data($column_key, $order_id) {
    
        // exit early if this is not the column we want
        if ('customer_role' != $column_key) {
            return;
        }
    
        $customer = new WC_Order( $order_id );
        if($customer->user_id != ''){
                $user = new WP_User( $customer->user_id );
                 if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
                foreach ( $user->roles as $role )
                   echo $role;
            }
        }
    
    }
    
  2. from https://stackoverflow.com/questions/30440471/woocommerce-orders-page-add-customer-role-custom-column by cc-by-sa and MIT license