atus' => array( 'description' => __( 'Stock status.', 'woocommerce' ), 'type' => 'string', 'enum' => array_keys( wc_get_product_stock_status_options() ), 'context' => array( 'view', 'edit' ), 'readonly' => true, ), 'stock_quantity' => array( 'description' => __( 'Stock quantity.', 'woocommerce' ), 'type' => 'integer', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), 'manage_stock' => array( 'description' => __( 'Manage stock.', 'woocommerce' ), 'type' => 'boolean', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), ), ); return $this->add_additional_fields_schema( $schema ); } /** * Get the query params for collections. * * @return array */ public function get_collection_params() { $params = parent::get_collection_params(); unset( $params['after'], $params['before'], $params['force_cache_refresh'] ); $params['exclude'] = array( 'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ), 'type' => 'array', 'items' => array( 'type' => 'integer', ), 'default' => array(), 'sanitize_callback' => 'wp_parse_id_list', ); $params['include'] = array( 'description' => __( 'Limit result set to specific ids.', 'woocommerce' ), 'type' => 'array', 'items' => array( 'type' => 'integer', ), 'default' => array(), 'sanitize_callback' => 'wp_parse_id_list', ); $params['offset'] = array( 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ), 'type' => 'integer', 'sanitize_callback' => 'absint', 'validate_callback' => 'rest_validate_request_arg', ); $params['order']['default'] = 'asc'; $params['orderby']['default'] = 'stock_status'; $params['orderby']['enum'] = $this->apply_custom_orderby_filters( array( 'stock_status', 'stock_quantity', 'date', 'id', 'include', 'title', 'sku', ) ); $params['parent'] = array( 'description' => __( 'Limit result set to those of particular parent IDs.', 'woocommerce' ), 'type' => 'array', 'items' => array( 'type' => 'integer', ), 'sanitize_callback' => 'wp_parse_id_list', 'default' => array(), ); $params['parent_exclude'] = array( 'description' => __( 'Limit result set to all items except those of a particular parent ID.', 'woocommerce' ), 'type' => 'array', 'items' => array( 'type' => 'integer', ), 'sanitize_callback' => 'wp_parse_id_list', 'default' => array(), ); $params['type'] = array( 'description' => __( 'Limit result set to items assigned a stock report type.', 'woocommerce' ), 'type' => 'string', 'default' => 'all', 'enum' => array_merge( array( 'all', 'lowstock' ), array_keys( wc_get_product_stock_status_options() ) ), ); return $params; } /** * Get the column names for export. * * @return array Key value pair of Column ID => Label. */ public function get_export_columns() { $export_columns = array( 'title' => __( 'Product / Variation', 'woocommerce' ), 'sku' => __( 'SKU', 'woocommerce' ), 'stock_status' => __( 'Status', 'woocommerce' ), 'stock_quantity' => __( 'Stock', 'woocommerce' ), ); /** * 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 ); } /** * 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 ) { $status = $item['stock_status']; if ( array_key_exists( $item['stock_status'], $this->status_options ) ) { $status = $this->status_options[ $item['stock_status'] ]; } $export_item = array( 'title' => $item['name'], 'sku' => $item['sku'], 'stock_status' => $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 ); } }