What is WC orders table?
WooCommerce provides a table with all the orders in WP dashboard area under WooCommerce > Orders.
By default that table has 7 columns: Order, Date, Status, Billing, Ship to, Total and Actions.
If you want to add a new column to this table in WordPress admin area, this is possible by adding custom PHP code to your functions.php file which it is in your theme folder.
How to add billing details to orders table
Let's say that, for example, you will want to add the billing details to this Orders table. You will need to open functions.php file which you can find it in your theme folder (yourdomain.com/wp-content/themes/your-theme/functions.php).
Then, at the end of this file, you will need to add the following PHP code in order to add a new "Billing Info" column at the end of the Orders table:
add_filter( 'manage_edit-shop_order_columns', 'zeninv_add_order_column_to_admin_table' );
function zeninv_add_order_column_to_admin_table( $columns ) {
$columns['billing_details'] = 'Billing Info';
return $columns;
}
add_action( 'manage_shop_order_posts_custom_column', 'zeninv_add_order_column_to_admin_table_content' );
function zeninv_add_order_column_to_admin_table_content( $column ) {
global $post;
if ( 'billing_details' === $column ) {
$order = wc_get_order( $post->ID );
echo $order->get_billing_first_name(); echo " ";
echo $order->get_billing_last_name(); echo "<br />";
echo $order->get_billing_company(); echo "<br />";
echo $order->get_billing_address_1(); echo ", ";
echo $order->get_billing_address_2(); echo "<br />";
echo $order->get_billing_city(); echo ", ";
echo $order->get_billing_state(); echo ", ";
echo $order->get_billing_postcode(); echo ", ";
echo $order->get_billing_country(); echo "<br />";
echo $order->get_billing_email(); echo "<br />";
echo $order->get_billing_phone();
}
}
The above code adds a new column at the end of the other existing columns in Orders table.
We add all billing fields, one by one, using PHP echo commands.
And now we have the desired result:
How to add other columns to the WC orders table?
The above code adds the billing info to the table. But you can add other columns to the orders table. All you have to do it to use the right WC tags. These tags are listed in WooCommerce documentation.
Please let me know if you have any questions and if this is working for you.
Comments closed
Please contact me, if you have any questions or suggestions.