Upendra Sharma Upendra Sharma - 5 months ago 416
PHP Question

WooCommerce: Add custom columns to admin orders list page

I am using WooCommerce plugin for one of my ecommerce Wordpress websites. I want to add some columns to my order listing page in the woocommerce admin area. I am not able to find out where to add that.

Can anyone advise which template page I need to amend in order to meet my requirement?

Answer

So you if you want to add some columns in the orders list of my account page:

You have to copy the templates directory located inside your woocommerce plugin to your active child theme or theme.
Then you have to rename it woocommerce.
Inside this woocommerce new renamed folder go to myaccount sub-folder. Then you can edit my-orders.php to fit your needs.


(UPDATE)

ADDING A COLUMN IN WOOCOMMERCE ADMIN ORDERS LIST

// ADDING COLUMN TITLES (Here 2 columns)
add_filter( 'manage_edit-shop_order_columns', 'custom_shop_order_column',11);
function custom_shop_order_column($columns)
{
   //add columns
    $columns['my-column1'] = __( 'Column Title','theme_slug');
    $columns['my-column2'] = __( 'Column Title','theme_slug');
   return $columns;
}

// adding the data for each orders by column (example)
add_action( 'manage_shop_order_posts_custom_column' , 'cbsp_credit_details', 10, 2 );
function cbsp_credit_details( $column )
{
    global $post, $woocommerce, $the_order;
    $order_id = $the_order->id;

    switch ( $column )
    {
        case 'my-column1' :
            $myVarOne = wc_get_order_item_meta( $order_id, '_the_meta_key1', true );
            echo $myVarOne;
            break;

        case 'my-column2' :
            $order_id = $the_order->id;
            $myVarTwo = wc_get_order_item_meta( $order_id, '_the_meta_key2', true );
            echo $myVarTwo;
            break;
    }
}