Orders::format_for_csv( array $items )
Formats the orders data for CSV export.
Contents
Parameters
- $items
-
(array) (Required) The orders data.
Return
(array) The formatted data ready for CSV export.
Source
File: src/Tickets/Commerce/Admin_Tables/Orders.php
public function format_for_csv( array $items ): array {
$csv_data = [];
// Use the values of get_columns() as CSV headers.
$csv_headers = array_values( $this->get_columns() );
$csv_data[] = $csv_headers;
// Iterate over each item and format the data.
foreach ( $items as $item ) {
$csv_row = [];
foreach ( array_keys( $this->get_columns() ) as $header ) {
$method_name = 'column_' . $header;
if ( method_exists(
$this,
$method_name
) ) {
// Dynamically call the method for the column.
$value = call_user_func(
[
$this,
$method_name,
],
$item
);
} else {
// Accessing the item properties directly using column_default.
$value = $this->column_default(
$item,
$header
);
}
$csv_row[] = $this->sanitize_and_format_csv_value( $value );
}
$csv_data[] = $csv_row;
}
return $csv_data;
}
Changelog
| Version | Description |
|---|---|
| 5.8.1 | Introduced. |