1

After updating to Woocommerce 3.0, in the Woocommerce ORDER page (where you can check all the orders made by customers, with order status, billing address, shipping address, total, etc.) is missing the column with the items purchased by the customer. Before WC update, that column was there. Now it is gone.

Could anyone help me to add again this column?

Thanks a lot!

2

3 Answers 3

1

I have already manage to create a column thanks to this:

    // ADDING COLUMN TITLES
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');
   return $columns;
}

// adding the data for each orders by column (example)
add_action( 'manage_shop_order_posts_custom_column' , 'custom_orders_list_column_content', 10, 2 );
function custom_orders_list_column_content( $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;
    }

But I don't know how to add the data to this columns. I need to add the items purchased by the customers. Is it possible?

Thanks!

1

I use this to add an Ordered Products column right after the Date column (fits nicely there). Each product is also linked to it's proper edit page.

// ----- add column to orders that shows which products were ordered -----
function ec_order_items_column($columns) {
    $new_columns = array();
    foreach($columns as $key=>$column){
        $new_columns[$key] = $columns[$key];
        if($key === 'order_date') {
            $new_columns['ordered_products'] = __('Ordered Products','woo-custom-ec');
        }
    }
    return $new_columns;

    //$columns['order_products'] = "Purchased Items";
    //return $columns;
}
add_filter('manage_edit-shop_order_columns', 'ec_order_items_column', 99 );

// ----- add data to new column that shows which products were ordered -----
function ec_order_items_column_cnt($column) {
    global $the_order; // the global order object
    if($column == 'ordered_products') {
        // get items from the order global object
        $order_items = $the_order->get_items();
        if (!is_wp_error($order_items)) {
            foreach($order_items as $order_item) {
                echo $order_item['quantity'].'&nbsp;&times;&nbsp;<a href="'.admin_url('post.php?post='.$order_item['product_id'].'&action=edit' ).'">'.$order_item['name'].'</a><br />';
            }
        }
    }
}
add_action('manage_shop_order_posts_custom_column', 'ec_order_items_column_cnt', 99);

enter image description here

6
  • At woocommerce 7.7 this not working when enable feature High-Performance order storage (COT). Have any update for this code?
    – vanloc
    Commented May 17, 2023 at 15:22
  • can you help me?
    – vanloc
    Commented May 17, 2023 at 16:12
  • My code above is a hook for wp_posts admin tables ... Enabling (HPOS) moves the orders out of wp_posts and into their own custom database tables ... I do not have any experience with (HPOS) yet so I do not have any modified code to mange (HPOS) order tables ... maybe some day, but not today.
    – Scotty G
    Commented May 18, 2023 at 16:29
  • Many thanks. Hope you help. Your code very short but it very helpful. I can see the name of product and quality order.
    – vanloc
    Commented May 19, 2023 at 7:28
  • hi @Scotty G, do you have time to research that code?
    – vanloc
    Commented May 24, 2023 at 10:42
0

If you want to display the purchased products in a column, you can use this code:

add_action( 'manage_shop_order_posts_custom_column' , 'custom_orders_list_column_content', 10, 2 );
function custom_orders_list_column_content( $column )
{
    global $the_order;
    $order_id = $the_order->id;

    switch ( $column )
    {
        case 'my-column1' :
            $order_items = $the_order->get_items();
            foreach( $order_items as $myVarOne ) {
                echo $myVarOne['quantity'] .'&nbsp;&times;&nbsp;'. $myVarOne['name'] .'<br />';
            }
            break;
    }
}

You can also view the complete code with screenshots in this tutorial.

Not the answer you're looking for? Browse other questions tagged or ask your own question.