Filter: wpd_alpha_insights_data_source_subscriptions
Filter the subscriptions entity data returned by the Subscriptions data source (WooCommerce Subscriptions) before it is stored in the data warehouse.
Description
After the subscriptions data source builds its data (totals, data_by_date, etc.), this filter is applied. You can modify subscription metrics or add custom keys. The data warehouse then stores the returned value for the subscriptions entity. Requires the WooCommerce Subscriptions plugin.
Location
File: includes/classes/data-sources/pro/WPDAI_Subscriptions_Data_Source.php
Context: When returning subscriptions data from the data source.
Parameters
| Parameter | Type | Description |
|---|---|---|
| $subscriptions_data | array | Subscriptions data structure (totals, data_by_date, total_db_records, etc.) |
| $data_warehouse | WPDAI_Data_Warehouse | The data warehouse instance |
Return
Type: array
The (possibly modified) subscriptions data structure.
Example Usage
Add a custom subscriptions metric
add_filter( 'wpd_alpha_insights_data_source_subscriptions', 'add_subscriptions_custom_metric', 10, 2 );
function add_subscriptions_custom_metric( $subscriptions_data, $data_warehouse ) {
if ( isset( $subscriptions_data['totals'] ) && is_array( $subscriptions_data['totals'] ) ) {
$subscriptions_data['totals']['mrr_estimate'] = 0; // Compute MRR from your logic
}
return $subscriptions_data;
}
Related
- Other data source filters: wpd_alpha_insights_data_source_sales, wpd_alpha_insights_data_source_store_profit