Filter the expenses entity data returned by the Expenses data source before it is stored in the data warehouse.
After the expenses data source builds its data structure (totals, data_by_date, data_table, etc.), this filter is applied. You can modify or add metrics, adjust totals, or alter time-series data. The data warehouse then stores the returned value for the expenses entity.
File: includes/classes/data-sources/pro/WPDAI_Expenses_Data_Source.php
Context: When returning expense data from the data source.
| Parameter | Type | Description |
|---|---|---|
| $expense_data | array | Expenses data structure (totals, categorized_data, data_table, data_by_date, total_db_records, etc.) |
| $data_warehouse | WPDAI_Data_Warehouse | The data warehouse instance (for date range, filters, or other entity data) |
Type: array
The (possibly modified) expenses data structure.
add_filter( 'wpd_alpha_insights_data_source_expenses', 'add_expense_custom_total', 10, 2 );
function add_expense_custom_total( $expense_data, $data_warehouse ) {
if ( isset( $expense_data['totals'] ) && is_array( $expense_data['totals'] ) ) {
$expense_data['totals']['my_custom_total'] = 100.00;
}
return $expense_data;
}