Admin Order Page – Order Column Meta Data?
-
Hi guys,
Need some help that has me baffled.
On the orders page (Admin area) we can see the order status, the order number + email address of the customer and so forth.
Question: How do I add the telephone number below the email address on the “Orders” column?
For clarification herewith a screen snippet – Screen Snippet
-
After tedious research I still can find the specific PHP file responsible for this, if someone could point me in the right direction I will be eternally grateful.
Hi!
Did you finally manage to achieve this? i’m trying to do the exact same thing but i haven’t find the way to do it yet.
Any help will be appreciated =)
Thanks!
@mj_diamond: If you require assistance then, as per the Forum Welcome, please post your own topic. This 3 month old topic may no longer be actively monitored.
Hi mj_diamond.
Have to report till date we still haven’t come right due to a lack of response on this thread and due to the fact that it’s a non critical task on the website we stopped looking.
However, if someone still knows how to do it we will welcome any assistance.
Hi again!
@paiconsultants, I finally figured it out! I hadn’t had the time to solve it before but after a couple of hours working on it, I got it! haha
The php file responsable for the columns in the orders admin page is located here:
wp-content/plugins/woocommerce/includes/admin/class-wc-admin-post-types.php
Anyway, editing that file directly is a bad idea because when you update Woocommerce, you lose all your changes. the best option is to use filters and edit the columns from your theme’s function.php file.
I didn’t find a way to just add the phone number below the email, in the “order” column, so i decided to unset that whole column, and create it again with my own data.
Here is the code (you have to put it in your theme’s function.php file):
add_filter( 'manage_edit-shop_order_columns', 'MY_COLUMNS_FUNCTION' ); function MY_COLUMNS_FUNCTION($columns){ $new_columns = (is_array($columns)) ? $columns : array(); //here we unset the "order_title" column (the one we are replacing) and all the columns after that one unset( $new_columns['order_title'] ); unset( $new_columns['order_items'] ); unset( $new_columns['shipping_address'] ); unset( $new_columns['customer_message'] ); unset( $new_columns['order_notes'] ); unset( $new_columns['order_date'] ); unset( $new_columns['order_total'] ); unset( $new_columns['order_actions'] ); //here we add our own column and we assign it the name "Pedido" or "Order" $new_columns['MY_COLUMN_ID_1'] = 'Pedido'; //here we add all the columns after that one, again, except for the original "order title" of course. $new_columns['order_items'] = $columns['order_items']; $new_columns['shipping_address'] = $columns['shipping_address']; $new_columns['customer_message'] = $columns['customer_message']; $new_columns['order_notes'] = $columns['order_notes']; $new_columns['order_date'] = $columns['order_date']; $new_columns['order_total'] = $columns['order_total']; $new_columns['order_actions'] = $columns['order_actions']; return $new_columns; } add_action( 'manage_shop_order_posts_custom_column', 'MY_COLUMNS_VALUES_FUNCTION', 2 ); function MY_COLUMNS_VALUES_FUNCTION($column){ global $post; $order_facory = new WC_Order_Factory(); $the_order = $order_facory->get_order( $post->ID ); if ( $column == 'MY_COLUMN_ID_1' ) { //here we paste the code from the "class-wc-admin-post-types.php" file (lines 710 to 750) //we are add the phone part almost at the end of it $customer_tip = array(); if ( $address = $the_order->get_formatted_billing_address() ) { $customer_tip[] = __( 'Billing:', 'woocommerce' ) . ' ' . $address . '<br/><br/>'; } if ( $the_order->billing_phone ) { $customer_tip[] = __( 'Tel:', 'woocommerce' ) . ' ' . $the_order->billing_phone; } if ( $the_order->user_id ) { $user_info = get_userdata( $the_order->user_id ); } if ( ! empty( $user_info ) ) { $username = '<a href="user-edit.php?user_id=' . absint( $user_info->ID ) . '">'; if ( $user_info->first_name || $user_info->last_name ) { $username .= esc_html( ucfirst( $user_info->first_name ) . ' ' . ucfirst( $user_info->last_name ) ); } else { $username .= esc_html( ucfirst( $user_info->display_name ) ); } $username .= '</a>'; } else { if ( $the_order->billing_first_name || $the_order->billing_last_name ) { $username = trim( $the_order->billing_first_name . ' ' . $the_order->billing_last_name ); } else { $username = __( 'Guest', 'woocommerce' ); } } printf( _x( '%s by %s', 'Order number by X', 'woocommerce' ), '<a href="' . admin_url( 'post.php?post=' . absint( $post->ID ) . '&action=edit' ) . '" class="row-title"><strong>#' . esc_attr( $the_order->get_order_number() ) . '</strong></a>', $username ); if ( $the_order->billing_email ) { echo '<small class="meta email"><a href="' . esc_url( 'mailto:' . $the_order->billing_email ) . '">' . esc_html( $the_order->billing_email ) . '</a></small>'; } //here we add the code to show the phone number, using the email code below as a reference if ( $the_order->billing_phone ) { echo '<small class="meta phone">Tel: ' . esc_html( $the_order->billing_phone ) . '</small>'; } //end of our phone code echo '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details', 'woocommerce' ) . '</span></button>'; } }
I really don’t know if this is the best way to do it, but it’s working, and at the end of the day, that’s what matters =)
If you have any doubt or problem with the code just let me know
Greetings!
You sir, are a Legend! It’s working perfectly!
Thank you for all your trouble, this has been a headache for so long.
Haha thank you =) i’m glad it’s working for you as well
Thank you for posting the question in the first place, it’s weird that nobody had asked about this before, but anyway, the solution will be here for anyone who needs it
Greetings!
Thank you mj_diamond!
It is awesome and working very well!
@mj_diamond you are awesome!
one more question – how to show cart subtotal near total in row?)
thank you in advance
one mor question)))
what to do with mobile version ?(
screenshot
https://www.dropbox.com/s/fmhw34h212jdel1/Screen%20Shot%202016-04-29%20at%2013.26.16.png?dl=0vuala
this is my fast CSS tweak for mobile version. Just add it to theme’s function.php file.
add_action('admin_head', 'kolua_tweak'); function kolua_tweak() { echo '<style> @media screen and (max-width:782px) { td.MY_COLUMN_ID_1.column-MY_COLUMN_ID_1 { display: block !important; } .post-type-shop_order .wp-list-table .toggle-row { top:15px!important; } </style>'; }
- The topic ‘Admin Order Page – Order Column Meta Data?’ is closed to new replies.