19

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?

mujuonly
  • 8,969
  • 5
  • 39
  • 68
Upendra Sharma
  • 505
  • 2
  • 8
  • 28
  • Do you mean, you want to add columns on 'cart' page? – zipkundan Apr 06 '16 at 09:18
  • Kindly read the following here https://wordpress.org/plugins/woocommerce-custom-product-data-fields/ – claudios Apr 06 '16 at 09:27
  • @claudios : i want to add those columns which are present in mysql order table with their values not any fields which are not available in database table – Upendra Sharma Apr 06 '16 at 09:30
  • For a look what i want here is the image https://www.dropbox.com/s/6s4956wsrnl83iz/imgpsh_fullsize.png?dl=0 – Upendra Sharma Apr 06 '16 at 10:45
  • there's no template override for admin area... can you explain more about your problem? please be specific about it too... – Reigel Apr 06 '16 at 11:20
  • @Reigel : When customer login to their account then they can see their previous order history or recent order history,,,,i want to add item image, item title and shipping customer column to that table. For clear explanation i am adding this image have a look https://www.dropbox.com/s/6s4956wsrnl83iz/imgpsh_fullsize.png?dl=0 – Upendra Sharma Apr 06 '16 at 13:49

1 Answers1

42

Updated: 2018-03-30 - added positioning feature to the new columns

So you if you want to add some columns in the orders Admin list page (in backend):

ADDING COLUMNS IN WOOCOMMERCE ADMIN ORDERS LIST

In the example below, we add 2 new custom columns, before existing "Total" and "Actions" columns.

// ADDING 2 NEW COLUMNS WITH THEIR TITLES (keeping "Total" and "Actions" columns at the end)
add_filter( 'manage_edit-shop_order_columns', 'custom_shop_order_column', 20 );
function custom_shop_order_column($columns)
{
    $reordered_columns = array();

    // Inserting columns to a specific location
    foreach( $columns as $key => $column){
        $reordered_columns[$key] = $column;
        if( $key ==  'order_status' ){
            // Inserting after "Status" column
            $reordered_columns['my-column1'] = __( 'Title1','theme_domain');
            $reordered_columns['my-column2'] = __( 'Title2','theme_domain');
        }
    }
    return $reordered_columns;
}

// Adding custom fields meta data for each new column (example)
add_action( 'manage_shop_order_posts_custom_column' , 'custom_orders_list_column_content', 20, 2 );
function custom_orders_list_column_content( $column, $post_id )
{
    switch ( $column )
    {
        case 'my-column1' :
            // Get custom post meta data
            $my_var_one = get_post_meta( $post_id, '_the_meta_key1', true );
            if(!empty($my_var_one))
                echo $my_var_one;

            // Testing (to be removed) - Empty value case
            else
                echo '<small>(<em>no value</em>)</small>';

            break;

        case 'my-column2' :
            // Get custom post meta data
            $my_var_two = get_post_meta( $post_id, '_the_meta_key2', true );
            if(!empty($my_var_two))
                echo $my_var_two;

            // Testing (to be removed) - Empty value case
            else
                echo '<small>(<em>no value</em>)</small>';

            break;
    }
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.

enter image description here


Related answer (for products): Add custom columns to admin producs list in WooCommerce backend

LoicTheAztec
  • 207,510
  • 22
  • 296
  • 340
  • 1
    This code is not fully correct - why is global $post needed, when $post is never used? Additionally there is a comma after $post, not a ';' - so this results in an error. Also - wc_get_order_item_meta is wrong here, this is used for items within the order, for the order itself get_post_meta must be used. – Torben Sep 12 '17 at 12:53
  • 1
    @Torben … This is an old answer and you are completely right… I make that changes. Sorry about. – LoicTheAztec Sep 12 '17 at 15:09
  • @LoicTheAztec thanks.. I works but i can not found column in wp_postmeta table. I also post my question https://wordpress.stackexchange.com/questions/301246/add-a-woocommerce-orders-list-column-and-value Please help – JH_ Apr 19 '18 at 10:39
  • @JH_ I never answer in WP stackexchange, as it's only for pure WordPress questions… You need to ask it Here in StackOverFlow… – LoicTheAztec Apr 19 '18 at 11:18
  • @LoicTheAztec Okay I Asked on stackoverflow here is link https://stackoverflow.com/questions/49919915/add-a-woocommerce-orders-list-column-and-value – JH_ Apr 19 '18 at 11:30
  • Please can you help me with how to display the highlighted value in the above column? I've tried adsw_order_number and _adsw_order_number with no luck. Thanks. https://i.postimg.cc/QMvbj6vc/Capture.png – Lyall Apr 25 '19 at 10:08
  • Never mind I figured it out using your answer here :) https://stackoverflow.com/a/39394661/4952851 – Lyall Apr 25 '19 at 12:17
  • How to get the Order Id here – Zam85 Jun 08 '20 at 14:01
  • 1
    @Zam85 use the variable $post_id – LoicTheAztec Jun 08 '20 at 14:04
  • 1
    @LoicTheAztec Thank You – Zam85 Jun 08 '20 at 14:09
  • @LoicTheAztec Works perfectly! Thank you! Now I'll look for having the possibility to sort the column by clicking the header. – yoan26 Jan 22 '21 at 15:58
  • @yoan26 see: https://stackoverflow.com/search?q=user%3A3730754+column+sortable – LoicTheAztec Jan 22 '21 at 16:06
  • 1
    Hey man, used this in 2021 & it still works perfectly. :) – Grant May 24 '21 at 02:52