I would like to display order_item of order in admin list like in this screenshot:

enter image description here

Changing
/woocommerce/includes/admin/list-tables/class-wc-admin-list-table-orders.php file, I tried to add the following:

$product = wc_get_product( $product_id );
$ss = $product->get_name();


echo $ss
echo $product->get_name();
echo get_the_title($product_id); // this one display the order date

But it didn’t work.

2 Answers
2

Never overwrite core files! for many reasons. Note that an order can have many items (products).

On orders admin list, the following will add item(s) (product(s)) names, to order status column:

add_action( 'manage_shop_order_posts_custom_column' , 'custom_orders_list_column_content', 20, 2 );
function custom_orders_list_column_content( $column, $post_id ) {
    global $the_order, $post;

    if ( 'order_status' === $column ) {
        $products_names = []; // Initializing

        // Loop through order items
        foreach ( $the_order->get_items() as $item ) {
            $product = $item->get_product(); // Get the WC_Product object
            $products_names[]  = $item->get_name(); // Store in an array
        }
        // Display
        echo '<ul style="list-style: none;"><li>' . implode('</li><li>', $products_names) . '</li></ul>';
    }
}

Code goes on functions.php file of your active child theme (or active theme). Tested and work.

Leave a Reply

Your email address will not be published. Required fields are marked *