Add filters for columns in reports (https://github.com/woocommerce/woocommerce-admin/pull/5134)
Co-authored-by: Rebecca Scott <me@becdetat.com>
This commit is contained in:
parent
f411c1aa51
commit
baad343599
|
@ -325,13 +325,24 @@ class Controller extends ReportsController implements ExportableInterface {
|
|||
* @return array Key value pair of Column ID => Label.
|
||||
*/
|
||||
public function get_export_columns() {
|
||||
return array(
|
||||
$export_columns = array(
|
||||
'category' => __( 'Category', 'woocommerce-admin' ),
|
||||
'items_sold' => __( 'Items Sold', 'woocommerce-admin' ),
|
||||
'net_revenue' => __( 'Net Revenue', 'woocommerce-admin' ),
|
||||
'products_count' => __( 'Products', 'woocommerce-admin' ),
|
||||
'orders_count' => __( 'Orders', 'woocommerce-admin' ),
|
||||
);
|
||||
|
||||
/**
|
||||
* Filter to add or remove column names from the categories report for
|
||||
* export.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
return apply_filters(
|
||||
'woocommerce_report_categories_export_columns',
|
||||
$export_columns
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -341,12 +352,24 @@ class Controller extends ReportsController implements ExportableInterface {
|
|||
* @return array Key value pair of Column ID => Row Value.
|
||||
*/
|
||||
public function prepare_item_for_export( $item ) {
|
||||
return array(
|
||||
$export_item = array(
|
||||
'category' => $item['extended_info']['name'],
|
||||
'items_sold' => $item['items_sold'],
|
||||
'net_revenue' => $item['net_revenue'],
|
||||
'products_count' => $item['products_count'],
|
||||
'orders_count' => $item['orders_count'],
|
||||
);
|
||||
|
||||
/**
|
||||
* Filter to prepare extra columns in the export item for the
|
||||
* categories export.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
return apply_filters(
|
||||
'woocommerce_report_categories_prepare_export_item',
|
||||
$export_item,
|
||||
$item
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -295,7 +295,7 @@ class Controller extends \WC_REST_Reports_Controller implements ExportableInterf
|
|||
* @return array Key value pair of Column ID => Label.
|
||||
*/
|
||||
public function get_export_columns() {
|
||||
return array(
|
||||
$export_columns = array(
|
||||
'code' => __( 'Coupon Code', 'woocommerce-admin' ),
|
||||
'orders_count' => __( 'Orders', 'woocommerce-admin' ),
|
||||
'amount' => __( 'Amount Discounted', 'woocommerce-admin' ),
|
||||
|
@ -303,6 +303,17 @@ class Controller extends \WC_REST_Reports_Controller implements ExportableInterf
|
|||
'expires' => __( 'Expires', 'woocommerce-admin' ),
|
||||
'type' => __( 'Type', 'woocommerce-admin' ),
|
||||
);
|
||||
|
||||
/**
|
||||
* Filter to add or remove column names from the coupons report for
|
||||
* export.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
return apply_filters(
|
||||
'woocommerce_report_coupons_export_columns',
|
||||
$export_columns
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -316,7 +327,7 @@ class Controller extends \WC_REST_Reports_Controller implements ExportableInterf
|
|||
? __( 'N/A', 'woocommerce-admin' )
|
||||
: $item['extended_info']['date_expires'];
|
||||
|
||||
return array(
|
||||
$export_item = array(
|
||||
'code' => $item['extended_info']['code'],
|
||||
'orders_count' => $item['orders_count'],
|
||||
'amount' => $item['amount'],
|
||||
|
@ -324,5 +335,17 @@ class Controller extends \WC_REST_Reports_Controller implements ExportableInterf
|
|||
'expires' => $date_expires,
|
||||
'type' => $item['extended_info']['discount_type'],
|
||||
);
|
||||
|
||||
/**
|
||||
* Filter to prepare extra columns in the export item for the coupons
|
||||
* report.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
return apply_filters(
|
||||
'woocommerce_report_coupons_prepare_export_item',
|
||||
$export_item,
|
||||
$item
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -582,7 +582,7 @@ class Controller extends \WC_REST_Reports_Controller implements ExportableInterf
|
|||
* @return array Key value pair of Column ID => Label.
|
||||
*/
|
||||
public function get_export_columns() {
|
||||
return array(
|
||||
$export_columns = array(
|
||||
'name' => __( 'Name', 'woocommerce-admin' ),
|
||||
'username' => __( 'Username', 'woocommerce-admin' ),
|
||||
'last_active' => __( 'Last Active', 'woocommerce-admin' ),
|
||||
|
@ -596,6 +596,17 @@ class Controller extends \WC_REST_Reports_Controller implements ExportableInterf
|
|||
'region' => __( 'Region', 'woocommerce-admin' ),
|
||||
'postcode' => __( 'Postal Code', 'woocommerce-admin' ),
|
||||
);
|
||||
|
||||
/**
|
||||
* Filter to add or remove column names from the customers report for
|
||||
* export.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
return apply_filters(
|
||||
'woocommerce_report_customers_export_columns',
|
||||
$export_columns
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -605,7 +616,7 @@ class Controller extends \WC_REST_Reports_Controller implements ExportableInterf
|
|||
* @return array Key value pair of Column ID => Row Value.
|
||||
*/
|
||||
public function prepare_item_for_export( $item ) {
|
||||
return array(
|
||||
$export_item = array(
|
||||
'name' => $item['name'],
|
||||
'username' => $item['username'],
|
||||
'last_active' => $item['date_last_active'],
|
||||
|
@ -619,5 +630,11 @@ class Controller extends \WC_REST_Reports_Controller implements ExportableInterf
|
|||
'region' => $item['state'],
|
||||
'postcode' => $item['postcode'],
|
||||
);
|
||||
|
||||
return apply_filters(
|
||||
'woocommerce_report_customers_prepare_export_item',
|
||||
$export_item,
|
||||
$item
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -393,7 +393,7 @@ class Controller extends ReportsController implements ExportableInterface {
|
|||
* @return array Key value pair of Column ID => Label.
|
||||
*/
|
||||
public function get_export_columns() {
|
||||
return array(
|
||||
$export_columns = array(
|
||||
'date' => __( 'Date', 'woocommerce-admin' ),
|
||||
'product' => __( 'Product Title', 'woocommerce-admin' ),
|
||||
'file_name' => __( 'File Name', 'woocommerce-admin' ),
|
||||
|
@ -401,6 +401,17 @@ class Controller extends ReportsController implements ExportableInterface {
|
|||
'user_id' => __( 'User Name', 'woocommerce-admin' ),
|
||||
'ip_address' => __( 'IP', 'woocommerce-admin' ),
|
||||
);
|
||||
|
||||
/**
|
||||
* Filter to add or remove column names from the downloads report for
|
||||
* export.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
return apply_filters(
|
||||
'woocommerce_filter_downloads_export_columns',
|
||||
$export_columns
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -410,7 +421,7 @@ class Controller extends ReportsController implements ExportableInterface {
|
|||
* @return array Key value pair of Column ID => Row Value.
|
||||
*/
|
||||
public function prepare_item_for_export( $item ) {
|
||||
return array(
|
||||
$export_columns = array(
|
||||
'date' => $item['date'],
|
||||
'product' => $item['_embedded']['product'][0]['name'],
|
||||
'file_name' => $item['file_name'],
|
||||
|
@ -418,5 +429,17 @@ class Controller extends ReportsController implements ExportableInterface {
|
|||
'user_id' => $item['username'],
|
||||
'ip_address' => $item['ip_address'],
|
||||
);
|
||||
|
||||
/**
|
||||
* Filter to prepare extra columns in the export item for the downloads
|
||||
* report.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
return apply_filters(
|
||||
'woocommerce_report_downloads_prepare_export_item',
|
||||
$export_item,
|
||||
$item
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -490,7 +490,7 @@ class Controller extends ReportsController implements ExportableInterface {
|
|||
* @return array Key value pair of Column ID => Label.
|
||||
*/
|
||||
public function get_export_columns() {
|
||||
return array(
|
||||
$export_columns = array(
|
||||
'date_created' => __( 'Date', 'woocommerce-admin' ),
|
||||
'order_number' => __( 'Order #', 'woocommerce-admin' ),
|
||||
'status' => __( 'Status', 'woocommerce-admin' ),
|
||||
|
@ -500,6 +500,17 @@ class Controller extends ReportsController implements ExportableInterface {
|
|||
'coupons' => __( 'Coupon(s)', 'woocommerce-admin' ),
|
||||
'net_total' => __( 'N. Revenue', 'woocommerce-admin' ),
|
||||
);
|
||||
|
||||
/**
|
||||
* Filter to add or remove column names from the orders report for
|
||||
* export.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
return apply_filters(
|
||||
'woocommerce_report_orders_export_columns',
|
||||
$export_columns
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -509,7 +520,7 @@ class Controller extends ReportsController implements ExportableInterface {
|
|||
* @return array Key value pair of Column ID => Row Value.
|
||||
*/
|
||||
public function prepare_item_for_export( $item ) {
|
||||
return array(
|
||||
$export_item = array(
|
||||
'date_created' => $item['date_created'],
|
||||
'order_number' => $item['order_number'],
|
||||
'status' => $item['status'],
|
||||
|
@ -519,5 +530,17 @@ class Controller extends ReportsController implements ExportableInterface {
|
|||
'coupons' => isset( $item['extended_info']['coupons'] ) ? $this->_get_coupons( $item['extended_info']['coupons'] ) : null,
|
||||
'net_total' => $item['net_total'],
|
||||
);
|
||||
|
||||
/**
|
||||
* Filter to prepare extra columns in the export item for the orders
|
||||
* report.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
return apply_filters(
|
||||
'woocommerce_report_orders_prepare_export_item',
|
||||
$export_item,
|
||||
$item
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -397,7 +397,16 @@ class Controller extends \WC_REST_Reports_Controller implements ExportableInterf
|
|||
$export_columns['stock'] = __( 'Stock', 'woocommerce-admin' );
|
||||
}
|
||||
|
||||
return $export_columns;
|
||||
/**
|
||||
* Filter to add or remove column names from the products report for
|
||||
* export.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
return apply_filters(
|
||||
'woocommerce_report_products_export_columns',
|
||||
$export_columns
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -427,6 +436,16 @@ class Controller extends \WC_REST_Reports_Controller implements ExportableInterf
|
|||
}
|
||||
}
|
||||
|
||||
return $export_item;
|
||||
/**
|
||||
* Filter to prepare extra columns in the export item for the products
|
||||
* report.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
return apply_filters(
|
||||
'woocommerce_report_products_prepare_export_item',
|
||||
$export_item,
|
||||
$item
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -520,12 +520,23 @@ class Controller extends \WC_REST_Reports_Controller implements ExportableInterf
|
|||
* @return array Key value pair of Column ID => Label.
|
||||
*/
|
||||
public function get_export_columns() {
|
||||
return array(
|
||||
$export_columns = array(
|
||||
'title' => __( 'Product / Variation', 'woocommerce-admin' ),
|
||||
'sku' => __( 'SKU', 'woocommerce-admin' ),
|
||||
'stock_status' => __( 'Status', 'woocommerce-admin' ),
|
||||
'stock_quantity' => __( 'Stock', 'woocommerce-admin' ),
|
||||
);
|
||||
|
||||
/**
|
||||
* Filter to add or remove column names from the stock report for
|
||||
* export.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
return apply_filters(
|
||||
'woocommerce_report_stock_export_columns',
|
||||
$export_columns
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -535,11 +546,23 @@ class Controller extends \WC_REST_Reports_Controller implements ExportableInterf
|
|||
* @return array Key value pair of Column ID => Row Value.
|
||||
*/
|
||||
public function prepare_item_for_export( $item ) {
|
||||
return array(
|
||||
$export_item = array(
|
||||
'title' => $item['name'],
|
||||
'sku' => $item['sku'],
|
||||
'stock_status' => $item['stock_status'],
|
||||
'stock_quantity' => $item['stock_quantity'],
|
||||
);
|
||||
|
||||
/**
|
||||
* Filter to prepare extra columns in the export item for the stock
|
||||
* report.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
return apply_filters(
|
||||
'woocommerce_report_stock_prepare_export_item',
|
||||
$export_item,
|
||||
$item
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue