Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to edit woocommerce admin order page?

I am using Woocommerce version 2.4.12, the latest one. I want to make some changes to orders page that is in the admin dashboard under woocommerce --> orders. Woocommerce Orders Page

Where is it's file in plugins->woocommerce folder? I have made a woocommerce folder in my theme to override template files. I want to add phone number of the customer to the ship_to column. Client wants Phone number of customer visible on the orders page. Any way to use functions.php to add a hook and make changes?

like image 964
Vivek Padhye Avatar asked Jan 14 '16 09:01

Vivek Padhye


2 Answers

try this to your functions.php

add_filter( 'manage_edit-shop_order_columns', 'shop_order_columns' );
function shop_order_columns( $columns ){
    $new_columns = (is_array($columns)) ? $columns : array();

    $new_columns['phone'] = 'Phone';

    return $new_columns;
}

add_action( 'manage_shop_order_posts_custom_column', 'shop_order_posts_custom_column' );
function shop_order_posts_custom_column( $column ){
    global $post, $the_order;

    if ( empty( $the_order ) || $the_order->get_id() != $post->ID ) {
        $the_order = wc_get_order( $post->ID );
    }

    $billing_address = $the_order->get_address();
    if ( $column == 'phone' ) {    
        echo ( isset( $billing_address['phone'] ) ? $billing_address['phone'] : '');
    }
}

Position problem??..

try this for the first function

function shop_order_columns($columns){
    $columns = (is_array($columns)) ? $columns : array();

    $phone = array( 'phone' => 'Phone' );
    $position = 5;
    $new_columns = array_slice( $columns, 0, $position, true ) +  $phone;

    return array_merge( $new_columns, $columns );
}

Updated for WooCommerce 3.

like image 166
Reigel Avatar answered Oct 02 '22 01:10

Reigel


You should use manage_shop_order_posts_custom_column action and change the column data by checking the column name

switch( $column ) {

        case 'shipping_address' :
            echo 'sample data';
            break;

    }
like image 44
Mehran Avatar answered Oct 02 '22 02:10

Mehran