WooCommerce Orders Page, Display Purchased Products

Add a custom column to your WooCommerce orders page showing all purchased products with quantities and direct links to product edit pages. Supports both legacy CPT-based and modern HPOS-based order storage.

// legacy – for CPT-based orders
add_filter( 'manage_edit-shop_order_columns', 'snn_woo_order_items_column' );

// for HPOS-based orders
add_filter( 'manage_woocommerce_page_wc-orders_columns', 'snn_woo_order_items_column' );

function snn_woo_order_items_column( $columns ) {
	// Insert "Purchased products" column at position 5 (before "Total")
	$columns = array_slice( $columns, 0, 4, true )
		+ array( 'order_products' => 'Purchased products' )
		+ array_slice( $columns, 4, NULL, true );

	return $columns;
}

// legacy – for CPT-based orders
add_action( 'manage_shop_order_posts_custom_column', 'snn_woo_populate_order_items_column', 25, 2 );

// for HPOS-based orders
add_action( 'manage_woocommerce_page_wc-orders_custom_column', 'snn_woo_populate_order_items_column', 25, 2 );

function snn_woo_populate_order_items_column( $column_name, $order_or_order_id ) {
	// Convert order ID to WC_Order object for compatibility with both CPT and HPOS
	$order = $order_or_order_id instanceof WC_Order ? $order_or_order_id : wc_get_order( $order_or_order_id );

	// Populate the purchased products column
	if ( 'order_products' === $column_name ) {
		$items = $order->get_items();

		// Display each product with quantity and link to edit
		if ( ! is_wp_error( $items ) ) {
			foreach ( $items as $item ) {
				echo $item['quantity'] . ' × <a href="' . get_edit_post_link( $item['product_id'] ) . '">' . $item['name'] . '</a><br />';
			}
		}
	}
}