Filter: wpd_alpha_insights_data_source_sales
Filter the sales (orders and related) entity data returned by the Sales data source before it is stored in the data warehouse.
Description
The Sales data source provides orders, products, customers, coupons, taxes, and refunds in one multi-entity response. After that data is built, this filter is applied with the full sales data structure. You can modify totals, data_by_date, or other keys. The data warehouse then stores the returned value (keyed by entity name) for each of those entities.
Location
File: includes/classes/data-sources/WPDAI_Sales_Data_Source.php
Context: When returning sales data from the data source.
Parameters
| Parameter | Type | Description |
|---|---|---|
| $sales_data | array | Multi-entity array: entity name => data structure (e.g. orders => array(…), products => array(…)) |
| $data_warehouse | WPDAI_Data_Warehouse | The data warehouse instance |
Return
Type: array
The (possibly modified) sales data structure (same multi-entity shape).
Example Usage
Adjust orders totals
add_filter( 'wpd_alpha_insights_data_source_sales', 'adjust_sales_orders_totals', 10, 2 );
function adjust_sales_orders_totals( $sales_data, $data_warehouse ) {
if ( isset( $sales_data['orders']['totals'] ) && is_array( $sales_data['orders']['totals'] ) ) {
// Example: add a custom key
$sales_data['orders']['totals']['my_adjusted_revenue'] = $sales_data['orders']['totals']['total_order_revenue_ex_tax'] ?? 0;
}
return $sales_data;
}
Related
- wpd_ai_calculate_cost_profit_by_order – Order profit calculation
- Other data source filters: wpd_alpha_insights_data_source_store_profit, wpd_alpha_insights_data_source_refunds