主要目标是在这些信息(净销售额、客户、订单、产品、已售商品)后面添加一个列表,其中包含“归因”以及每个归因的总和(美元)。 我必须将归因栏放在列表下方(图 1)
我尝试通过在functions.php上添加函数来更改class-wc-report-sales-by-date.php中的数据,但没有任何反应。我几乎确定我做错了,但我有点迷失了。
$this->report_data->total_coupons = number_format(array_sum(wp_list_pluck($this->report_data->coupons, 'discount_amount')), 2, '.', '');
在 Functions.php 上:
function custom_admin_report_data($report_data)
{
// HERE you make your calculations and changes
// New amout to set (example)
$new_calculated_amount = 100;
//number_format(array_sum(wp_list_pluck($this->report_data->coupons, 'discount_amount')), 2, '.', '');
// Set the new amounts for "total_coupons" key
$report_data->total_coupons = $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;
}
add_filter('woocommerce_admin_report_data', 'custom_admin_report_data', 10, 1);
尝试将过滤器从
woocommerce_admin_report_data
更改为 woocommerce_reports_get_order_report_data
add_filter('woocommerce_reports_get_order_report_data', 'custom_modify_sales_by_date_report_data', 10, 1);
function custom_modify_sales_by_date_report_data($data) {
// Check if we are in the sales by date report context
if (isset($data->total_coupons)) {
$new_calculated_amount = 100;
$data->total_coupons = $new_calculated_amount;
}
return $data;
}