Filter the store profit entity data returned by the Store Profit data source before it is stored in the data warehouse.
Store profit is derived from orders and expenses (e.g. P&L). After the Store Profit data source builds its structure (totals, data_by_date, etc.), this filter is applied. You can modify profit metrics or add custom keys. The data warehouse then stores the returned value for the store_profit entity.
File: includes/classes/data-sources/WPDAI_Store_Profit_Data_Source.php
Context: When returning store profit data from the data source.
| Parameter | Type | Description |
|---|---|---|
| $store_profit_data | array | Store profit data structure (totals, data_by_date, total_db_records, etc.) |
| $data_warehouse | WPDAI_Data_Warehouse | The data warehouse instance |
Type: array
The (possibly modified) store profit data structure.
add_filter( 'wpd_alpha_insights_data_source_store_profit', 'add_store_profit_custom_metric', 10, 2 );
function add_store_profit_custom_metric( $store_profit_data, $data_warehouse ) {
if ( isset( $store_profit_data['totals'] ) && is_array( $store_profit_data['totals'] ) ) {
$profit = $store_profit_data['totals']['total_store_profit'] ?? 0;
$store_profit_data['totals']['profit_after_tax_estimate'] = $profit * 0.8;
}
return $store_profit_data;
}