Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • mj_diamond

    (@mj_diamond)

    Same problem here, it’s driving me crazy!

    did you find any solution or workaround?

    Thank you!

    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!

    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!

    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!

Viewing 4 replies - 1 through 4 (of 4 total)