This example adds Email Address and Phone Number columns to the Report by order details table, using the two filters the table exposes.
Before you start
- Email Reports 2.9 or later. These filters were added in 2.9.
- The Report by order details table must be enabled on the report, in the Report Details panel. If the table is off, the filters never run and your columns will not appear.
- Somewhere to put custom PHP — a site-specific plugin, a code snippets plugin, or your child theme’s
functions.php. - A backup, and ideally a staging site to try it on first.
The code
Both filters take an array and must return it. Add one header cell and one body cell per column, in the same order, or the columns will not line up.
// Add the column headers.
add_filter( 'sre_order_details_table_header', 'my_order_details_header', 10, 1 );
function my_order_details_header( $columns ) {
$columns[] = 'Email Address';
$columns[] = 'Phone Number';
return $columns;
}
// Add the matching cell for each order row.
add_filter( 'sre_order_details_table_content', 'my_order_details_content', 10, 2 );
function my_order_details_content( $cells, $order ) {
$cells[] = $order->get_billing_email();
$cells[] = $order->get_billing_phone();
return $cells;
}
Name your callbacks something of your own
Do not name the callback function the same as the filter it hooks to. Earlier versions of this example did, which works but makes the code confusing to read and risks colliding with another snippet. Prefix your functions, as above.
How it works
| Filter | What it receives | What to return |
|---|---|---|
sre_order_details_table_header | The array of column headings. | The same array with your headings appended. |
sre_order_details_table_content | The array of cells for one row, plus the WC_Order object for that row. | The same array with your cell values appended, in the same order as the headings. |
Because you get the full WC_Order object, you can output anything on the order — a meta field, the shipping method, the customer note — not just billing details.
Testing it
Send yourself a test report — it uses live data, so you’ll see your columns filled in straight away.
Troubleshooting
| Problem | Check |
|---|---|
| The columns don’t appear at all | The Report by order details table is enabled on this report, and you’re running Email Reports 2.9 or later. |
| Headers appear but cells are empty | The orders actually have that data — a guest order may have no phone number, for example. |
| Columns are misaligned | You added a different number of header cells and body cells, or added them in a different order. |
| Something broke after adding the code | Remove the snippet and check whether the problem persists before looking elsewhere. |
See also: Custom Columns for Top Selling Products.