我正在尝试向 woocommerce 分析中的订单提供的表中添加一列,显示该订单名称(不是产品名称)。
例如,我有一个产品名称“Bookings”,我的订单名称是“Booking - Archery”。
我修改了woocommerce分析相关的文件,
\wordpress\wp-content\plugins\woocommerce\packages\woocommerce-admin\src\API\Reports\Orders\Controller.php,
并添加了以下代码:
(下面的代码使用“//”来标记我个人添加的部分)
/**
* Get the Report's schema, conforming to JSON Schema.
*
* @return array
*/
public function get_item_schema() {
$schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'report_orders',
'type' => 'object',
'properties' => array(
'order_id' => array(
'description' => __( 'Order ID.', 'woocommerce' ),
'type' => 'integer',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'order_number' => array(
'description' => __( 'Order Number.', 'woocommerce' ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
// add order item name info in report
'order_item_name' => array(
'description' => __( 'Order Item Name.', 'woocommerce' ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
'readonly' => true,
), ......
/**
* Get the column names for export.
*
* @return array Key value pair of Column ID => Label.
*/
public function get_export_columns() {
$export_columns = array(
'date_created' => __( 'Date', 'woocommerce' ),
'order_number' => __( 'Order #', 'woocommerce' ),
'status' => __( 'Status', 'woocommerce' ),
'customer_type' => __( 'Customer', 'woocommerce' ),
'products' => __( 'Product(s)', 'woocommerce' ),
// add "Item Name" column
'order_item_name' => __( 'Item Name', 'woocommerce' ),
'num_items_sold' => __( 'Items Sold', 'woocommerce' ),
'coupons' => __( 'Coupon(s)', 'woocommerce' ),
'net_total' => __( 'N. Revenue', 'woocommerce' ),
);
/**
* Get the column values for export.
*
* @param array $item Single report item/row.
* @return array Key value pair of Column ID => Row Value.
*/
public function prepare_item_for_export( $item ) {
$export_item = array(
'date_created' => $item['date_created'],
'order_number' => $item['order_number'],
'status' => $item['status'],
'customer_type' => $item['customer_type'],
'products' => isset( $item['extended_info']['products'] ) ? $this->_get_products( $item['extended_info']['products'] ) : null,
//add order item name value in the table
'order_item_name' => $item['order_item_name'],
'num_items_sold' => $item['num_items_sold'],
'coupons' => isset( $item['extended_info']['coupons'] ) ? $this->_get_coupons( $item['extended_info']['coupons'] ) : null,
'net_total' => $item['net_total'],
);
但是我保存controller.php刷新页面后,订单报表表没有添加新的列,点击下载报表时,csv文件也没有显示新的列。
通过调试,没有发现我的代码引用了数据库中_SLL_woocommerce_order_items表中的order_item_name。 我认为我的代码缺少一些重要的部分,所以想请问一下如何修改才能更改出效果?
你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答
本次提问扣除的有问必答次数,已经为您补发到账户,我们后续会持续优化,扩大我们的服务范围,为您带来更好地服务。