Website Building » WooCommerce » How Do I Add a Column in WooCommerce Orders Page?

How Do I Add a Column in WooCommerce Orders Page?

Last updated on January 14, 2023 @ 11:08 am

Adding a column to the WooCommerce orders page can be a useful way to display additional information to customers and store owners. Here is a step-by-step guide on how to add a new column to the WooCommerce orders page:

  1. First, you will need to create a new function that will add the new column. This can be done by creating a new PHP file and adding the following code:
function add_new_column_to_orders($columns) {
  $new_columns = array();
   foreach($columns as $key => $value) {
     $new_columns[$key] = $value;
     if($key == 'order_title') {
        $new_columns['new_column'] = __('New Column', 'woocommerce');
     }
   }
return $new_columns;
}
add_filter('manage_edit-shop_order_columns', 'add_new_column_to_orders');

This code creates a new function called “add_new_column_to_orders” which adds a new column called “New Column” to the orders page.

  1. Next, you will need to add the content for the new column. This can be done by adding the following code to the same PHP file:
function add_content_to_new_column($column) {
  global $post;
  if($column == 'new_column') {
   echo get_post_meta($post->ID, 'new_column', true);
  }
}
add_action('manage_shop_order_posts_custom_column', 'add_content_to_new_column');

This code creates a new function called “add_content_to_new_column” which will display the content for the new column.

  1. Finally, you will need to add some CSS to style the new column. You can do this by adding the following code to your theme’s stylesheet:
th#new_column {
  width: 150px;
}

This code sets the width of the new column to 150px.

Once you have added these code snippets, you should now be able to see the new column on the WooCommerce orders page. You can further customize this column by adding custom data to the order meta data, or by adding a custom query to pull data from other tables.

Note: Remember to add the code snippet in your child theme functions.php file or in a plugin file to avoid loosing the changes on theme updates.

Morgan Bash

Morgan Bash

Technology enthusiast and Co-Founder of Women Coders SF.