Wordpress 覆盖“商业报告”部分中的功能

Wordpress 覆盖“商业报告”部分中的功能,wordpress,woocommerce,report,hook-woocommerce,orders,Wordpress,Woocommerce,Report,Hook Woocommerce,Orders,我需要在WooCommerce中自定义报告,因此我必须编辑核心文件class wc report sales by date.php,这样的文件不使用任何挂钩 在WC源代码中检查此项: 我必须编辑393行,这个变量:$this->report\u data->total\u sales 我需要自定义总销售额以增加另一个价值 如何覆盖此核心文件?永远不要覆盖核心文件…还有其他方法可以实现这一点。如果您查看第411行,您有woocommerce\u admin\u report\u数据过滤器钩子来进

我需要在WooCommerce中自定义报告,因此我必须编辑核心文件
class wc report sales by date.php
,这样的文件不使用任何挂钩

在WC源代码中检查此项:

我必须编辑393行,这个变量:$this->report\u data->total\u sales 我需要自定义总销售额以增加另一个价值


如何覆盖此核心文件?

永远不要覆盖核心文件…还有其他方法可以实现这一点。如果您查看
第411行
,您有
woocommerce\u admin\u report\u数据
过滤器钩子来进行更改,方法如下(示例):

因此,正如您所见,您还需要对“orders”对象数据进行更改,因为您还有
“total_sales”


谢谢这就是我需要的。非常感谢您的时间和帮助:)这是否也可以操作数据或在“按产品销售”中的图表侧栏/图例中添加其他项目,此筛选器仅影响“按日期销售”?
add_filter( 'woocommerce_admin_report_data', 'custom_admin_report_data', 10, 1 );
function custom_admin_report_data( $report_data ){
    // HERE you make your calculations and changes
    // New amout to set (example)
    $new_calculated_amount = 100;

    // Set the new amounts for "total_sales" key
    $report_data->total_sales = $new_calculated_amount;

    // Raw data output just for testing, to get the keys and the structure of the data
    // to be removed
    echo '<pre>'; print_r($report_data); echo '</pre>';

    // Return the changed data object
    return $report_data;
}