In this one we’ll show you how to add a custom column in the Orders table in WooCommerce Admin dashboard. This way you can easily add and view order meta (or custom field) information you need at glance, without viewing the order itself.

This tutorial has two parts. First off we’ll add the column in the WooCommerce admin order view table. Then we’ll populate the meta info in it.

PHP Snippet: Add custom column to WooCommerce admin orders list

In order to add a new column in the orders table, we’ll use the manage_edit-shop_order_columns filter. In your child theme’s functions.php file add the following code:

function webroom_add_order_new_column_header( $columns ) {

    $new_columns = array();

    foreach ( $columns as $column_name => $column_info ) {

        $new_columns[ $column_name ] = $column_info;

        if ( 'order_total' === $column_name ) {
            $new_columns['order_details'] = __( 'Details', 'my-textdomain' );
        }
    }

    return $new_columns;
}
add_filter( 'manage_edit-shop_order_columns', 'webroom_add_order_new_column_header', 20);

Now, we’ve created a new column named “Details”. You can choose a name of your own. Remember to change both ‘order_details’ and ‘Details’ in the above code. We’ve placed the column ‘Details’ right after the Total column.

Now It’s empty so lets add some data.

PHP Snippet: add order meta data in WooCommerce admin orders table

For demo purpose we’ll add the billing phone to the custom column. In functions.php add the following snippet:

add_action( 'manage_shop_order_posts_custom_column', 'webroom_add_wc_order_admin_list_column_content' );
 
function webroom_add_wc_order_admin_list_column_content( $column ) {
   
    global $post;
 
    if ( 'order_details' === $column ) {
 
        $order = wc_get_order( $post->ID );
        echo '<p>Phone: ' . $order->get_billing_phone() . '</p>';
      
    }
}

Here you have to change ‘order_details’ according to the first snippet which creates the column. The next thing to change is the echo part where we actually display the desired order data (or any data we want). In the example we are showing the billing phone.

Learn more about the action hooks we used in this tutorial:

Need help with WordPress or WooCommerce?

Visit our Community Forums

Ask a Question

Recent Articles

From Our Community Forums

Blog Categories

Comments

Leave a comment
  1. Thomassen Henneberg April 26, 2020 at 5:18 am - Reply

    Enjoyed reading the content above, actually explains everything in detail,
    the guide is very interesting and effective. Thank you and good luck in the articles.

    King regards,
    Thomassen Henneberg

  2. Sven April 18, 2020 at 7:24 pm - Reply

    Hi!

    Thanks for your tutorial.
    Do you know how to make that new column searchable?

    Best regards,

Leave a Reply

Comment policy: We love comments and appreciate the time that readers spend to share ideas and give feedback. However, all comments are manually moderated and those deemed to be spam or solely promotional will be deleted.