This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

📣 Join the live AMA session with Adam Silverstein on open source and WordPress core! Register Now →

Add a WooCommerce Orders List Column

Updated on April 22, 2021

2 Min Read

Every WooCommerce Orders list has columns that highlight various details about the order. While these columns could be easily remove through the Screen Options tab, the addition of the columns requires custom code that adds a column to the list.

WooCommerce Order Column

Add a Header

The addition of a custom columns is done through manage_edit-{$post_type}_columns filter (part of the WordPress core). By using this filter, I could change the columns in the list table  and inject my own column(s).

function wc_new_order_column( $columns ) {
$columns['my_column'] = 'My column';
return $columns;
add_filter( 'manage_edit-shop_order_columns', 'wc_new_order_column' );

Now I am going to add a column in my intended position.  This would be a new Profit column that would come after the total column for the order.

function cw_add_order_profit_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_profit'] = __('Profit', 'my-textdomain');
        }
    }
    return $new_columns;
}

add_filter('manage_edit-shop_order_columns', 'cw_add_order_profit_column_header');

Now we can use that to get the profit for the order and add it to the column.

function cw_add_order_profit_column_content( $column ) {
    global $post;

    if ( 'order_profit' === $column ) {

        $order    = wc_get_order( $post->ID );
        $currency = is_callable( array( $order, 'get_currency' ) ) ? $order->get_currency() : $order->order_currency;
        $profit   = '';
        $cost     = sv_helper_get_order_meta( $order, '_wc_cog_order_total_cost' );
        $total    = (float) $order->get_total();

               if ( '' !== $cost || false !== $cost ) {

            $cost   = (float) $cost;
            $profit = $total - $cost;
        }

        echo wc_price( $profit, array( 'currency' => $currency ) );
    }
}
add_action( 'manage_shop_order_posts_custom_column', 'cw_add_order_profit_column_content' );

Now, the following is optional. I will make the Profit column the same width as the total column. I will add custom CSS to the existing stylesheet by using the function wp_add_inline_style. I will add this to woocommerce_admin_styles:

function cw_add_order_profit_column_style() {

    $css = '.widefat .column-order_date, .widefat .column-order_profit { width: 9%; }';
    wp_add_inline_style( 'woocommerce_admin_styles', $css );
}
add_action( 'admin_print_styles', 'cw_add_order_profit_column_style' );

Adding custom columns to WooCommerce order list is a matter of adding code through a filter. If you need help with the code and the process of adding the custom columns, do leave a comment below and I will get back to you ASAP.

Q. How do I print a list of orders in WooCommerce?

Here’s how you can print a list of orders in WooCommerce:

  • Go to your WordPress dashboard.
  • Navigate to WooCommerce > Orders.
  • Select the orders you want to print.
  • Click on the “Print” button to generate a printable list.

Q. How do I get all order details in WooCommerce?

You can use the wc_get_orders() function to retrieve all order details programmatically in WooCommerce.

Q. How do I create a custom order field in WooCommerce?

You can use the woocommerce_new_order and woocommerce_process_shop_order_meta hooks to add and save custom order fields in WooCommerce.

Q. Which table are WooCommerce orders stored in?

WooCommerce orders are stored in the “wp_posts table” with a post_type of “shop_order“.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Owais Alam

is the WordPress Community Manager at Cloudways - A Managed WooCommerce Hosting Platform and a seasoned PHP developer. He loves to develop all sorts of websites on WordPress and is in love with WooCommerce in particular. You can email him at [email protected]

×

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Thankyou for Subscribing Us!

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour

CYBER WEEK SAVINGS

  • 0

    Days

  • 0

    Hours

  • 0

    Mints

  • 0

    Sec

GET OFFER

For 4 Months &
40 Free Migrations

For 4 Months &
40 Free Migrations

Upgrade Now