Home > other >  Display user description in WooCommerce admin order edit pages after billing address
Display user description in WooCommerce admin order edit pages after billing address

Time:01-15

I need to display customer Bio in WooCommerce admin order edit pages after the billing address.

Actually I only succeeded to display in a column like that:

column

With this code:

 // Adding a custom new column to admin orders list
add_filter( 'manage_edit-shop_order_columns', 'custom_column_eldest_players', 20 );
function custom_column_eldest_players($columns)
{
    $reordered_columns = array();

    // Inserting columns to a specific location
    foreach( $columns as $key => $column){
        $reordered_columns[$key] = $column;
        if( $key ==  'order_status' ){
            // Inserting after "Status" column
            $reordered_columns['user-bio'] = __( 'Note client', 'woocommerce');
        }
    }
    return $reordered_columns;
}

// Adding custom fields meta data for the column
add_action( 'manage_shop_order_posts_custom_column' , 'custom_orders_list_column_content', 20, 2 );
function custom_orders_list_column_content( $column, $post_id ) {
    if ( 'user-bio' === $column ) {
        global $the_order;

        echo ( $user = $the_order->get_user() ) ? $user->description : 'n/c';
    }
}

But I don't know how to insert in WooCommerce admin order edit pages. Any advice?

CodePudding user response:

Do display the user description on the admin order pages after billing adress you can use the woocommerce_admin_order_data_after_billing_address acton hook.

So you get:

// Display on admin order pages after billing adress
function action_woocommerce_admin_order_data_after_billing_address( $order ) {  
    // Get user
    $user = $order->get_user();
    
    // Initialize
    $output = __( 'Bio: ', 'woocommerce' );

    // Is a WP user
    if ( is_a( $user, 'WP_User' ) ) {
        ! empty( $user->description ) ? $output .= $user->description : $output .= __( 'n/c', 'woocommerce' );
    } else {
        $output .= __( 'n/c', 'woocommerce' );
    }
    
    // Output
    echo $output;
}
add_action( 'woocommerce_admin_order_data_after_billing_address', 'action_woocommerce_admin_order_data_after_billing_address', 10, 1 );
  •  Tags:  
  • Related