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.

PHP Snippet: show order private notes in WooCommerce admin orders table

Here is how to show order Private notes:

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 );
        $args = array(
            'order_id' => $post->ID,
        );

  		$notes = wc_get_order_notes( $args );
        foreach ( $notes as $note ) {
            $css_class   = array( 'note' );
            $css_class[] = $note->customer_note ? 'customer-note' : '';
            $css_class[] = 'system' === $note->added_by ? 'system-note' : '';
            $css_class   = apply_filters( 'woocommerce_order_note_class', array_filter( $css_class ), $note );
            ?>
            <li rel="<?php echo absint( $note->id ); ?>" class="<?php echo esc_attr( implode( ' ', $css_class ) ); ?>">
                <div class="note_content">
                    <?php echo wpautop( wptexturize( wp_kses_post( $note->content ) ) ); // @codingStandardsIgnoreLine ?>
                </div>
                <p class="meta">
                    <abbr class="exact-date" title="<?php echo esc_attr( $note->date_created->date( 'Y-m-d H:i:s' ) ); ?>">
                        <?php
                        /* translators: %1$s: note date %2$s: note time */
                        echo esc_html( sprintf( __( '%1$s at %2$s', 'woocommerce' ), $note->date_created->date_i18n( wc_date_format() ), $note->date_created->date_i18n( wc_time_format() ) ) );
                        ?>
                    </abbr>
                    <?php
                    if ( 'system' !== $note->added_by ) :
                        /* translators: %s: note author */
                        echo esc_html( sprintf( ' ' . __( 'by %s', 'woocommerce' ), $note->added_by ) );
                    endif;
                    ?>
                    <a href="#" class="delete_note" role="button" rel="nofollow ugc"><?php esc_html_e( 'Delete note', 'woocommerce' ); ?></a>
                </p>
            </li>
            <?php
        }
      
    }
}

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




Recent Articles

From Our Community Forums

Blog Categories

Related Articles

If you enjoyed reading this, then please explore our other articles below:

Comments

Leave a comment
  1. Ady July 23, 2020 at 8:49 am - Reply

    Please, how can I show my “Private notes”. Is it possible to show with this snippet? Thank you.

    • webroom July 23, 2020 at 2:09 pm - Reply

      Hi, Ady! I’ve added third snippet in the article above which shows the Private notes.

      You can remove the meta paragraph if you don’t need it.

      Take care :)

  2. Alec July 16, 2020 at 1:10 am - Reply

    Great tutorial. I learned a lot.

    I sell digital downloads and want to add a column to show if the customer downloaded the product.
    Currently I have to go to each order to see if the download counter still says 0 or 1….2….3…. etc.

    I tries adding- $order->get_downloadable_items(); but comes back as an “array”.
    Is this even possible with this type of code?

    Thank you
    Newbie

  3. webroom June 21, 2020 at 7:32 am - Reply

    Here’s how to get all the order information when using $order = wc_get_order( $post->ID );

    // Get Order ID and Key
    $order->get_id();
    $order->get_order_key();

    // Get Order Totals $0.00
    $order->get_formatted_order_total();
    $order->get_cart_tax();
    $order->get_currency();
    $order->get_discount_tax();
    $order->get_discount_to_display();
    $order->get_discount_total();
    $order->get_fees();
    $order->get_formatted_line_subtotal();
    $order->get_shipping_tax();
    $order->get_shipping_total();
    $order->get_subtotal();
    $order->get_subtotal_to_display();
    $order->get_tax_location();
    $order->get_tax_totals();
    $order->get_taxes();
    $order->get_total();
    $order->get_total_discount();
    $order->get_total_tax();
    $order->get_total_refunded();
    $order->get_total_tax_refunded();
    $order->get_total_shipping_refunded();
    $order->get_item_count_refunded();
    $order->get_total_qty_refunded();
    $order->get_qty_refunded_for_item();
    $order->get_total_refunded_for_item();
    $order->get_tax_refunded_for_item();
    $order->get_total_tax_refunded_by_rate_id();
    $order->get_remaining_refund_amount();

    // Get and Loop Over Order Items
    foreach ( $order->get_items() as $item_id => $item ) {
    $product_id = $item->get_product_id();
    $variation_id = $item->get_variation_id();
    $product = $item->get_product();
    $name = $item->get_name();
    $quantity = $item->get_quantity();
    $subtotal = $item->get_subtotal();
    $total = $item->get_total();
    $tax = $item->get_subtotal_tax();
    $taxclass = $item->get_tax_class();
    $taxstat = $item->get_tax_status();
    $allmeta = $item->get_meta_data();
    $somemeta = $item->get_meta( '_whatever', true );
    $type = $item->get_type();
    }

    // Other Secondary Items Stuff
    $order->get_items_key();
    $order->get_items_tax_classes();
    $order->get_item_count();
    $order->get_item_total();
    $order->get_downloadable_items();

    // Get Order Lines
    $order->get_line_subtotal();
    $order->get_line_tax();
    $order->get_line_total();

    // Get Order Shipping
    $order->get_shipping_method();
    $order->get_shipping_methods();
    $order->get_shipping_to_display();

    // Get Order Dates
    $order->get_date_created();
    $order->get_date_modified();
    $order->get_date_completed();
    $order->get_date_paid();

    // Get Order User, Billing & Shipping Addresses
    $order->get_customer_id();
    $order->get_user_id();
    $order->get_user();
    $order->get_customer_ip_address();
    $order->get_customer_user_agent();
    $order->get_created_via();
    $order->get_customer_note();
    $order->get_address_prop();
    $order->get_billing_first_name();
    $order->get_billing_last_name();
    $order->get_billing_company();
    $order->get_billing_address_1();
    $order->get_billing_address_2();
    $order->get_billing_city();
    $order->get_billing_state();
    $order->get_billing_postcode();
    $order->get_billing_country();
    $order->get_billing_email();
    $order->get_billing_phone();
    $order->get_shipping_first_name();
    $order->get_shipping_last_name();
    $order->get_shipping_company();
    $order->get_shipping_address_1();
    $order->get_shipping_address_2();
    $order->get_shipping_city();
    $order->get_shipping_state();
    $order->get_shipping_postcode();
    $order->get_shipping_country();
    $order->get_address();
    $order->get_shipping_address_map_url();
    $order->get_formatted_billing_full_name();
    $order->get_formatted_shipping_full_name();
    $order->get_formatted_billing_address();
    $order->get_formatted_shipping_address();

    // Get Order Payment Details
    $order->get_payment_method();
    $order->get_payment_method_title();
    $order->get_transaction_id();

    // Get Order URLs
    $order->get_checkout_payment_url();
    $order->get_checkout_order_received_url();
    $order->get_cancel_order_url();
    $order->get_cancel_order_url_raw();
    $order->get_cancel_endpoint();
    $order->get_view_order_url();
    $order->get_edit_order_url();

    // Get Order Status
    $order->get_status();

  4. marcel June 20, 2020 at 9:13 pm - Reply

    how get order comment ? for display in details for example ? In your example, you get phone :

    $order = wc_get_order( $post->ID );
    echo ‘Phone: ‘ . $order->get_billing_phone() . ”;

    but order notes ?

    • webroom June 21, 2020 at 7:29 am - Reply

      Hi! Try using

      $order->get_customer_note();

      echo ‘Order Notes: ‘ . $order->get_customer_note(); . ”;

      This is for Woocommerce 3+.

  5. Chealsie June 10, 2020 at 5:43 pm - Reply

    Awesome article just had one question. Is there a way I can call $order->get_description(); in my code after adding the column?

    • webroom June 21, 2020 at 7:36 am - Reply

      If you are using WooCommerce 3.0 or above, then you can get description with the below code.

      $order = wc_get_order($order_id);

      foreach ($order->get_items() as $item) {
      $product_id = $item['product_id'];
      $product_details = $product->get_data();

      $product_full_description = $product_details['description'];
      $product_short_description = $product_details['short_description'];
      }

      Alternate way (recommended)

      $order = wc_get_order($order_id);

      foreach ($order->get_items() as $item) {
      $product_id = $item['product_id'];
      $product_instance = wc_get_product($product_id);

      $product_full_description = $product_instance->get_description();
      $product_short_description = $product_instance->get_short_description();
      }

  6. 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

  7. 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.