=> 'array', 'items' => array( 'type' => 'integer', ), 'default' => array(), 'sanitize_callback' => 'wp_parse_id_list', 'validate_callback' => 'rest_validate_request_arg', ); $params['coupon_excludes'] = array( 'description' => __( 'Limit result set to items that don\'t have the specified coupon(s) assigned.', 'woocommerce' ), 'type' => 'array', 'items' => array( 'type' => 'integer', ), 'default' => array(), 'validate_callback' => 'rest_validate_request_arg', 'sanitize_callback' => 'wp_parse_id_list', ); $params['tax_rate_includes'] = array( 'description' => __( 'Limit result set to items that have the specified tax rate(s) assigned.', 'woocommerce' ), 'type' => 'array', 'items' => array( 'type' => 'integer', ), 'default' => array(), 'sanitize_callback' => 'wp_parse_id_list', 'validate_callback' => 'rest_validate_request_arg', ); $params['tax_rate_excludes'] = array( 'description' => __( 'Limit result set to items that don\'t have the specified tax rate(s) assigned.', 'woocommerce' ), 'type' => 'array', 'items' => array( 'type' => 'integer', ), 'default' => array(), 'validate_callback' => 'rest_validate_request_arg', 'sanitize_callback' => 'wp_parse_id_list', ); $params['status_is'] = array( 'description' => __( 'Limit result set to items that have the specified order status.', 'woocommerce' ), 'type' => 'array', 'sanitize_callback' => 'wp_parse_slug_list', 'validate_callback' => 'rest_validate_request_arg', 'items' => array( 'enum' => self::get_order_statuses(), 'type' => 'string', ), ); $params['status_is_not'] = array( 'description' => __( 'Limit result set to items that don\'t have the specified order status.', 'woocommerce' ), 'type' => 'array', 'sanitize_callback' => 'wp_parse_slug_list', 'validate_callback' => 'rest_validate_request_arg', 'items' => array( 'enum' => self::get_order_statuses(), 'type' => 'string', ), ); $params['customer_type'] = array( 'description' => __( 'Limit result set to returning or new customers.', 'woocommerce' ), 'type' => 'string', 'default' => '', 'enum' => array( '', 'returning', 'new', ), 'validate_callback' => 'rest_validate_request_arg', ); $params['refunds'] = array( 'description' => __( 'Limit result set to specific types of refunds.', 'woocommerce' ), 'type' => 'string', 'default' => '', 'enum' => array( '', 'all', 'partial', 'full', 'none', ), 'validate_callback' => 'rest_validate_request_arg', ); $params['extended_info'] = array( 'description' => __( 'Add additional piece of info about each coupon to the report.', 'woocommerce' ), 'type' => 'boolean', 'default' => false, 'sanitize_callback' => 'wc_string_to_bool', 'validate_callback' => 'rest_validate_request_arg', ); $params['order_includes'] = array( 'description' => __( 'Limit result set to items that have the specified order ids.', 'woocommerce' ), 'type' => 'array', 'sanitize_callback' => 'wp_parse_id_list', 'validate_callback' => 'rest_validate_request_arg', 'items' => array( 'type' => 'integer', ), ); $params['order_excludes'] = array( 'description' => __( 'Limit result set to items that don\'t have the specified order ids.', 'woocommerce' ), 'type' => 'array', 'sanitize_callback' => 'wp_parse_id_list', 'validate_callback' => 'rest_validate_request_arg', 'items' => array( 'type' => 'integer', ), ); $params['attribute_is'] = array( 'description' => __( 'Limit result set to orders that include products with the specified attributes.', 'woocommerce' ), 'type' => 'array', 'items' => array( 'type' => 'array', ), 'default' => array(), 'validate_callback' => 'rest_validate_request_arg', ); $params['attribute_is_not'] = array( 'description' => __( 'Limit result set to orders that don\'t include products with the specified attributes.', 'woocommerce' ), 'type' => 'array', 'items' => array( 'type' => 'array', ), 'default' => array(), 'validate_callback' => 'rest_validate_request_arg', ); $params['force_cache_refresh'] = array( 'description' => __( 'Force retrieval of fresh data instead of from the cache.', 'woocommerce' ), 'type' => 'boolean', 'sanitize_callback' => 'wp_validate_boolean', 'validate_callback' => 'rest_validate_request_arg', ); return $params; } /** * Get customer name column export value. * * @param array $customer Customer from report row. * @return string */ protected function get_customer_name( $customer ) { return $customer['first_name'] . ' ' . $customer['last_name']; } /** * Get products column export value. * * @param array $products Products from report row. * @return string */ protected function get_products( $products ) { $products_list = array(); foreach ( $products as $product ) { $products_list[] = sprintf( /* translators: 1: numeric product quantity, 2: name of product */ __( '%1$s× %2$s', 'woocommerce' ), $product['quantity'], $product['name'] ); } return implode( ', ', $products_list ); } /** * Get coupons column export value. * * @param array $coupons Coupons from report row. * @return string */ protected function get_coupons( $coupons ) { return implode( ', ', wp_list_pluck( $coupons, 'code' ) ); } /** * 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' ), 'total_formatted' => __( 'N. Revenue (formatted)', 'woocommerce' ), 'status' => __( 'Status', 'woocommerce' ), 'customer_name' => __( 'Customer', 'woocommerce' ), 'customer_type' => __( 'Customer type', 'woocommerce' ), 'products' => __( 'Product(s)', 'woocommerce' ), 'num_items_sold' => __( 'Items sold', 'woocommerce' ), 'coupons' => __( 'Coupon(s)', 'woocommerce' ), 'net_total' => __( 'N. Revenue', 'woocommerce' ), 'attribution' => __( 'Attribution', 'woocommerce' ), ); /** * 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 ); } /** * 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'], 'total_formatted' => $item['total_formatted'], 'status' => $item['status'], 'customer_name' => isset( $item['extended_info']['customer'] ) ? $this->get_customer_name( $item['extended_info']['customer'] ) : null, 'customer_type' => $item['customer_type'], 'products' => isset( $item['extended_info']['products'] ) ? $this->get_products( $item['extended_info']['products'] ) : null, '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'], 'attribution' => $item['extended_info']['attribution']['origin'], ); /** * 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 ); } }