Filter: wpd_alpha_insights_data_source_refunds

Filter the refunds entity data returned by the Refunds data source before it is stored in the data warehouse.

Description

After the refunds data source builds its data (totals, data_by_date, data_table, etc.), this filter is applied. You can modify refund metrics or adjust the structure. The data warehouse then stores the returned value for the refunds entity. The filter is applied in multiple places where refunds data is returned.

Location

File: includes/classes/data-sources/WPDAI_Refunds_Internal_Data_Source.php

Context: When returning refunds data from the data source.

Parameters

Parameter Type Description
$refunds_data array Refunds data structure (totals, data_by_date, data_table, total_db_records, etc.)
$data_warehouse WPDAI_Data_Warehouse The data warehouse instance

Return

Type: array

The (possibly modified) refunds data structure.

Example Usage

Add a custom refund total

add_filter( 'wpd_alpha_insights_data_source_refunds', 'add_refunds_custom_total', 10, 2 );
function add_refunds_custom_total( $refunds_data, $data_warehouse ) {
    if ( isset( $refunds_data['totals'] ) && is_array( $refunds_data['totals'] ) ) {
        $refunds_data['totals']['refunds_excluding_shipping'] = $refunds_data['totals']['total_refunded_amount'] ?? 0;
    }
    return $refunds_data;
}

Related