How to edit woocommerce admin order page?

2019-02-06 21:19发布

问题:

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.

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?

回答1:

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.



回答2:

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;

    }