This snippets allows you to add a custom column to the Orders table under My Account which will be populated with products from the order. Implementing this snippet allows your customers see from a top level view which products are part of which order without having to tirelessly drill-down into each order to see which products have been order. By reducing the number of clicks the customer has to make to find out basic information, greatly improves the customer experience as they get the information they are after more quickly.
/**
* Snippet Name: WooCommerce Show Products Ordered In My Account Orders Table
* Snippet Author: ecommercehints.com
*/
// First, create the new table column between Date and Status columns
add_filter( 'woocommerce_my_account_my_orders_columns', 'ecommercehints_product_column_my_account_orders_table', 10, 1 );
function ecommercehints_product_column_my_account_orders_table( $columns ) {
$product_column = [];
foreach ( $columns as $key => $name ) {
$product_column[ $key ] = $name;
if ( 'order-date' === $key ) {
$product_column['order-items'] = __( 'Product', 'woocommerce' );
}
}
return $product_column;
}
// Second, insert the data from the order into the new column
add_action( 'woocommerce_my_account_my_orders_column_order-items', 'ecommercehints_get_product_data', 10, 1 );
function ecommercehints_get_product_data( $order ) {
$details = array();
foreach( $order->get_items() as $item ) {
$product = $item->get_product();
$product_permalink = get_permalink( $product->get_id() );
$details[] = '' . $item->get_name() . ' × ' . $item->get_quantity() . '';
}
echo count( $details ) > 0 ? implode( '
', $details ) : '–';
}