Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Admin/API/Reports/Stock
File: Controller.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* REST API Reports stock controller
[2] Fix | Delete
*
[3] Fix | Delete
* Handles requests to the /reports/stock endpoint.
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
namespace Automattic\WooCommerce\Admin\API\Reports\Stock;
[7] Fix | Delete
[8] Fix | Delete
defined( 'ABSPATH' ) || exit;
[9] Fix | Delete
[10] Fix | Delete
use Automattic\WooCommerce\Admin\API\Reports\GenericController;
[11] Fix | Delete
use Automattic\WooCommerce\Admin\API\Reports\ExportableInterface;
[12] Fix | Delete
use Automattic\WooCommerce\Enums\ProductType;
[13] Fix | Delete
use WP_REST_Request;
[14] Fix | Delete
use WP_REST_Response;
[15] Fix | Delete
use Automattic\WooCommerce\Enums\ProductStockStatus;
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* REST API Reports stock controller class.
[19] Fix | Delete
*
[20] Fix | Delete
* @internal
[21] Fix | Delete
* @extends GenericController
[22] Fix | Delete
*/
[23] Fix | Delete
class Controller extends GenericController implements ExportableInterface {
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Route base.
[27] Fix | Delete
*
[28] Fix | Delete
* @var string
[29] Fix | Delete
*/
[30] Fix | Delete
protected $rest_base = 'reports/stock';
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* Registered stock status options.
[34] Fix | Delete
*
[35] Fix | Delete
* @var array
[36] Fix | Delete
*/
[37] Fix | Delete
protected $status_options;
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* Constructor.
[41] Fix | Delete
*/
[42] Fix | Delete
public function __construct() {
[43] Fix | Delete
$this->status_options = wc_get_product_stock_status_options();
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
/**
[47] Fix | Delete
* Maps query arguments from the REST request.
[48] Fix | Delete
*
[49] Fix | Delete
* @param WP_REST_Request $request Request array.
[50] Fix | Delete
* @return array
[51] Fix | Delete
*/
[52] Fix | Delete
protected function prepare_reports_query( $request ) {
[53] Fix | Delete
$args = array();
[54] Fix | Delete
$args['offset'] = $request['offset'];
[55] Fix | Delete
$args['order'] = $request['order'];
[56] Fix | Delete
$args['orderby'] = $request['orderby'];
[57] Fix | Delete
$args['paged'] = $request['page'];
[58] Fix | Delete
$args['post__in'] = $request['include'];
[59] Fix | Delete
$args['post__not_in'] = $request['exclude'];
[60] Fix | Delete
$args['posts_per_page'] = $request['per_page'];
[61] Fix | Delete
$args['post_parent__in'] = $request['parent'];
[62] Fix | Delete
$args['post_parent__not_in'] = $request['parent_exclude'];
[63] Fix | Delete
[64] Fix | Delete
if ( 'date' === $args['orderby'] ) {
[65] Fix | Delete
$args['orderby'] = 'date ID';
[66] Fix | Delete
} elseif ( 'include' === $args['orderby'] ) {
[67] Fix | Delete
$args['orderby'] = 'post__in';
[68] Fix | Delete
} elseif ( 'id' === $args['orderby'] ) {
[69] Fix | Delete
$args['orderby'] = 'ID'; // ID must be capitalized.
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
$args['post_type'] = array( 'product', 'product_variation' );
[73] Fix | Delete
[74] Fix | Delete
if ( ProductStockStatus::LOW_STOCK === $request['type'] ) {
[75] Fix | Delete
$args['low_in_stock'] = true;
[76] Fix | Delete
} elseif ( in_array( $request['type'], array_keys( $this->status_options ), true ) ) {
[77] Fix | Delete
$args['stock_status'] = $request['type'];
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
$args['ignore_sticky_posts'] = true;
[81] Fix | Delete
[82] Fix | Delete
return $args;
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
/**
[86] Fix | Delete
* Query products.
[87] Fix | Delete
*
[88] Fix | Delete
* @param array $query_args Query args.
[89] Fix | Delete
* @return array
[90] Fix | Delete
*/
[91] Fix | Delete
protected function get_products( $query_args ) {
[92] Fix | Delete
$query = new \WP_Query();
[93] Fix | Delete
$result = $query->query( $query_args );
[94] Fix | Delete
[95] Fix | Delete
$total_posts = $query->found_posts;
[96] Fix | Delete
if ( $total_posts < 1 && isset( $query_args['paged'] ) && absint( $query_args['paged'] ) > 1 ) {
[97] Fix | Delete
// Out-of-bounds, run the query again without LIMIT for total count.
[98] Fix | Delete
unset( $query_args['paged'] );
[99] Fix | Delete
$count_query = new \WP_Query();
[100] Fix | Delete
$count_query->query( $query_args );
[101] Fix | Delete
$total_posts = $count_query->found_posts;
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
return array(
[105] Fix | Delete
'objects' => array_map( 'wc_get_product', $result ),
[106] Fix | Delete
'total' => (int) $total_posts,
[107] Fix | Delete
'pages' => (int) ceil( $total_posts / (int) $query->query_vars['posts_per_page'] ),
[108] Fix | Delete
);
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
/**
[112] Fix | Delete
* Get all reports.
[113] Fix | Delete
*
[114] Fix | Delete
* @param WP_REST_Request $request Request data.
[115] Fix | Delete
* @return array|WP_Error
[116] Fix | Delete
*/
[117] Fix | Delete
public function get_items( $request ) {
[118] Fix | Delete
add_filter( 'posts_where', array( __CLASS__, 'add_wp_query_filter' ), 10, 2 );
[119] Fix | Delete
add_filter( 'posts_join', array( __CLASS__, 'add_wp_query_join' ), 10, 2 );
[120] Fix | Delete
add_filter( 'posts_groupby', array( __CLASS__, 'add_wp_query_group_by' ), 10, 2 );
[121] Fix | Delete
add_filter( 'posts_clauses', array( __CLASS__, 'add_wp_query_orderby' ), 10, 2 );
[122] Fix | Delete
$query_args = $this->prepare_reports_query( $request );
[123] Fix | Delete
$query_results = $this->get_products( $query_args );
[124] Fix | Delete
remove_filter( 'posts_where', array( __CLASS__, 'add_wp_query_filter' ), 10 );
[125] Fix | Delete
remove_filter( 'posts_join', array( __CLASS__, 'add_wp_query_join' ), 10 );
[126] Fix | Delete
remove_filter( 'posts_groupby', array( __CLASS__, 'add_wp_query_group_by' ), 10 );
[127] Fix | Delete
remove_filter( 'posts_clauses', array( __CLASS__, 'add_wp_query_orderby' ), 10 );
[128] Fix | Delete
[129] Fix | Delete
$objects = array();
[130] Fix | Delete
foreach ( $query_results['objects'] as $object ) {
[131] Fix | Delete
$data = $this->prepare_item_for_response( $object, $request );
[132] Fix | Delete
$objects[] = $this->prepare_response_for_collection( $data );
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
return $this->add_pagination_headers(
[136] Fix | Delete
$request,
[137] Fix | Delete
$objects,
[138] Fix | Delete
(int) $query_results['total'],
[139] Fix | Delete
(int) $query_args['paged'],
[140] Fix | Delete
(int) $query_results['pages']
[141] Fix | Delete
);
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
/**
[145] Fix | Delete
* Add in conditional search filters for products.
[146] Fix | Delete
*
[147] Fix | Delete
* @internal
[148] Fix | Delete
* @param string $where Where clause used to search posts.
[149] Fix | Delete
* @param object $wp_query WP_Query object.
[150] Fix | Delete
* @return string
[151] Fix | Delete
*/
[152] Fix | Delete
public static function add_wp_query_filter( $where, $wp_query ) {
[153] Fix | Delete
global $wpdb;
[154] Fix | Delete
[155] Fix | Delete
$stock_status = $wp_query->get( 'stock_status' );
[156] Fix | Delete
if ( $stock_status ) {
[157] Fix | Delete
$where .= $wpdb->prepare(
[158] Fix | Delete
' AND wc_product_meta_lookup.stock_status = %s ',
[159] Fix | Delete
$stock_status
[160] Fix | Delete
);
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
if ( $wp_query->get( 'low_in_stock' ) ) {
[164] Fix | Delete
// We want products with stock < low stock amount, but greater than no stock amount.
[165] Fix | Delete
$no_stock_amount = absint( max( get_option( 'woocommerce_notify_no_stock_amount' ), 0 ) );
[166] Fix | Delete
$low_stock_amount = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) );
[167] Fix | Delete
$where .= "
[168] Fix | Delete
AND wc_product_meta_lookup.stock_quantity IS NOT NULL
[169] Fix | Delete
AND wc_product_meta_lookup.stock_status = 'instock'
[170] Fix | Delete
AND (
[171] Fix | Delete
(
[172] Fix | Delete
low_stock_amount_meta.meta_value > ''
[173] Fix | Delete
AND wc_product_meta_lookup.stock_quantity <= CAST(low_stock_amount_meta.meta_value AS SIGNED)
[174] Fix | Delete
AND wc_product_meta_lookup.stock_quantity > {$no_stock_amount}
[175] Fix | Delete
)
[176] Fix | Delete
OR (
[177] Fix | Delete
(
[178] Fix | Delete
low_stock_amount_meta.meta_value IS NULL OR low_stock_amount_meta.meta_value <= ''
[179] Fix | Delete
)
[180] Fix | Delete
AND wc_product_meta_lookup.stock_quantity <= {$low_stock_amount}
[181] Fix | Delete
AND wc_product_meta_lookup.stock_quantity > {$no_stock_amount}
[182] Fix | Delete
)
[183] Fix | Delete
)";
[184] Fix | Delete
}
[185] Fix | Delete
[186] Fix | Delete
return $where;
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
/**
[190] Fix | Delete
* Join posts meta tables when product search or low stock query is present.
[191] Fix | Delete
*
[192] Fix | Delete
* @internal
[193] Fix | Delete
* @param string $join Join clause used to search posts.
[194] Fix | Delete
* @param object $wp_query WP_Query object.
[195] Fix | Delete
* @return string
[196] Fix | Delete
*/
[197] Fix | Delete
public static function add_wp_query_join( $join, $wp_query ) {
[198] Fix | Delete
global $wpdb;
[199] Fix | Delete
[200] Fix | Delete
$stock_status = $wp_query->get( 'stock_status' );
[201] Fix | Delete
if ( $stock_status ) {
[202] Fix | Delete
$join = self::append_product_sorting_table_join( $join );
[203] Fix | Delete
}
[204] Fix | Delete
[205] Fix | Delete
if ( $wp_query->get( 'low_in_stock' ) ) {
[206] Fix | Delete
$join = self::append_product_sorting_table_join( $join );
[207] Fix | Delete
$join .= " LEFT JOIN {$wpdb->postmeta} AS low_stock_amount_meta ON {$wpdb->posts}.ID = low_stock_amount_meta.post_id AND low_stock_amount_meta.meta_key = '_low_stock_amount' ";
[208] Fix | Delete
}
[209] Fix | Delete
[210] Fix | Delete
return $join;
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
/**
[214] Fix | Delete
* Join wc_product_meta_lookup to posts if not already joined.
[215] Fix | Delete
*
[216] Fix | Delete
* @internal
[217] Fix | Delete
* @param string $sql SQL join.
[218] Fix | Delete
* @return string
[219] Fix | Delete
*/
[220] Fix | Delete
protected static function append_product_sorting_table_join( $sql ) {
[221] Fix | Delete
global $wpdb;
[222] Fix | Delete
[223] Fix | Delete
if ( ! strstr( $sql, 'wc_product_meta_lookup' ) ) {
[224] Fix | Delete
$sql .= " LEFT JOIN {$wpdb->wc_product_meta_lookup} wc_product_meta_lookup ON $wpdb->posts.ID = wc_product_meta_lookup.product_id ";
[225] Fix | Delete
}
[226] Fix | Delete
return $sql;
[227] Fix | Delete
}
[228] Fix | Delete
[229] Fix | Delete
/**
[230] Fix | Delete
* Group by post ID to prevent duplicates.
[231] Fix | Delete
*
[232] Fix | Delete
* @internal
[233] Fix | Delete
* @param string $groupby Group by clause used to organize posts.
[234] Fix | Delete
* @param object $wp_query WP_Query object.
[235] Fix | Delete
* @return string
[236] Fix | Delete
*/
[237] Fix | Delete
public static function add_wp_query_group_by( $groupby, $wp_query ) {
[238] Fix | Delete
global $wpdb;
[239] Fix | Delete
[240] Fix | Delete
if ( empty( $groupby ) ) {
[241] Fix | Delete
$groupby = $wpdb->posts . '.ID';
[242] Fix | Delete
}
[243] Fix | Delete
return $groupby;
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
/**
[247] Fix | Delete
* Custom orderby clauses using the lookup tables.
[248] Fix | Delete
*
[249] Fix | Delete
* @internal
[250] Fix | Delete
* @param array $args Query args.
[251] Fix | Delete
* @param object $wp_query WP_Query object.
[252] Fix | Delete
* @return array
[253] Fix | Delete
*/
[254] Fix | Delete
public static function add_wp_query_orderby( $args, $wp_query ) {
[255] Fix | Delete
global $wpdb;
[256] Fix | Delete
[257] Fix | Delete
$orderby = $wp_query->get( 'orderby' );
[258] Fix | Delete
$order = esc_sql( $wp_query->get( 'order' ) ? $wp_query->get( 'order' ) : 'desc' );
[259] Fix | Delete
[260] Fix | Delete
switch ( $orderby ) {
[261] Fix | Delete
case 'stock_quantity':
[262] Fix | Delete
$args['join'] = self::append_product_sorting_table_join( $args['join'] );
[263] Fix | Delete
$args['orderby'] = " wc_product_meta_lookup.stock_quantity {$order}, wc_product_meta_lookup.product_id {$order} ";
[264] Fix | Delete
break;
[265] Fix | Delete
case 'stock_status':
[266] Fix | Delete
$args['join'] = self::append_product_sorting_table_join( $args['join'] );
[267] Fix | Delete
$args['orderby'] = " wc_product_meta_lookup.stock_status {$order}, wc_product_meta_lookup.stock_quantity {$order} ";
[268] Fix | Delete
break;
[269] Fix | Delete
case 'sku':
[270] Fix | Delete
$args['join'] = self::append_product_sorting_table_join( $args['join'] );
[271] Fix | Delete
$args['orderby'] = " wc_product_meta_lookup.sku {$order}, wc_product_meta_lookup.product_id {$order} ";
[272] Fix | Delete
break;
[273] Fix | Delete
}
[274] Fix | Delete
[275] Fix | Delete
return $args;
[276] Fix | Delete
}
[277] Fix | Delete
[278] Fix | Delete
/**
[279] Fix | Delete
* Prepare a report data item for serialization.
[280] Fix | Delete
*
[281] Fix | Delete
* @param WC_Product $product Report data item as returned from Data Store.
[282] Fix | Delete
* @param WP_REST_Request $request Request object.
[283] Fix | Delete
* @return WP_REST_Response
[284] Fix | Delete
*/
[285] Fix | Delete
public function prepare_item_for_response( $product, $request ) {
[286] Fix | Delete
$data = array(
[287] Fix | Delete
'id' => $product->get_id(),
[288] Fix | Delete
'parent_id' => $product->get_parent_id(),
[289] Fix | Delete
'name' => wp_strip_all_tags( $product->get_name() ),
[290] Fix | Delete
'sku' => $product->get_sku(),
[291] Fix | Delete
'stock_status' => $product->get_stock_status(),
[292] Fix | Delete
'stock_quantity' => (float) $product->get_stock_quantity(),
[293] Fix | Delete
'manage_stock' => $product->get_manage_stock(),
[294] Fix | Delete
'low_stock_amount' => $product->get_low_stock_amount(),
[295] Fix | Delete
);
[296] Fix | Delete
[297] Fix | Delete
if ( '' === $data['low_stock_amount'] ) {
[298] Fix | Delete
$data['low_stock_amount'] = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) );
[299] Fix | Delete
}
[300] Fix | Delete
[301] Fix | Delete
$response = parent::prepare_item_for_response( $data, $request );
[302] Fix | Delete
$response->add_links( $this->prepare_links( $product ) );
[303] Fix | Delete
[304] Fix | Delete
/**
[305] Fix | Delete
* Filter a report returned from the API.
[306] Fix | Delete
*
[307] Fix | Delete
* Allows modification of the report data right before it is returned.
[308] Fix | Delete
*
[309] Fix | Delete
* @param WP_REST_Response $response The response object.
[310] Fix | Delete
* @param WC_Product $product The original product object.
[311] Fix | Delete
* @param WP_REST_Request $request Request used to generate the response.
[312] Fix | Delete
*/
[313] Fix | Delete
return apply_filters( 'woocommerce_rest_prepare_report_stock', $response, $product, $request );
[314] Fix | Delete
}
[315] Fix | Delete
[316] Fix | Delete
/**
[317] Fix | Delete
* Prepare links for the request.
[318] Fix | Delete
*
[319] Fix | Delete
* @param WC_Product $product Object data.
[320] Fix | Delete
* @return array
[321] Fix | Delete
*/
[322] Fix | Delete
protected function prepare_links( $product ) {
[323] Fix | Delete
if ( $product->is_type( ProductType::VARIATION ) ) {
[324] Fix | Delete
$links = array(
[325] Fix | Delete
'product' => array(
[326] Fix | Delete
'href' => rest_url( sprintf( '/%s/products/%d/variations/%d', $this->namespace, $product->get_parent_id(), $product->get_id() ) ),
[327] Fix | Delete
),
[328] Fix | Delete
'parent' => array(
[329] Fix | Delete
'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $product->get_parent_id() ) ),
[330] Fix | Delete
),
[331] Fix | Delete
);
[332] Fix | Delete
} elseif ( $product->get_parent_id() ) {
[333] Fix | Delete
$links = array(
[334] Fix | Delete
'product' => array(
[335] Fix | Delete
'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $product->get_id() ) ),
[336] Fix | Delete
),
[337] Fix | Delete
'parent' => array(
[338] Fix | Delete
'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $product->get_parent_id() ) ),
[339] Fix | Delete
),
[340] Fix | Delete
);
[341] Fix | Delete
} else {
[342] Fix | Delete
$links = array(
[343] Fix | Delete
'product' => array(
[344] Fix | Delete
'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $product->get_id() ) ),
[345] Fix | Delete
),
[346] Fix | Delete
);
[347] Fix | Delete
}
[348] Fix | Delete
[349] Fix | Delete
return $links;
[350] Fix | Delete
}
[351] Fix | Delete
[352] Fix | Delete
/**
[353] Fix | Delete
* Get the Report's schema, conforming to JSON Schema.
[354] Fix | Delete
*
[355] Fix | Delete
* @return array
[356] Fix | Delete
*/
[357] Fix | Delete
public function get_item_schema() {
[358] Fix | Delete
$schema = array(
[359] Fix | Delete
'$schema' => 'http://json-schema.org/draft-04/schema#',
[360] Fix | Delete
'title' => 'report_stock',
[361] Fix | Delete
'type' => 'object',
[362] Fix | Delete
'properties' => array(
[363] Fix | Delete
'id' => array(
[364] Fix | Delete
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
[365] Fix | Delete
'type' => 'integer',
[366] Fix | Delete
'context' => array( 'view', 'edit' ),
[367] Fix | Delete
'readonly' => true,
[368] Fix | Delete
),
[369] Fix | Delete
'parent_id' => array(
[370] Fix | Delete
'description' => __( 'Product parent ID.', 'woocommerce' ),
[371] Fix | Delete
'type' => 'integer',
[372] Fix | Delete
'context' => array( 'view', 'edit' ),
[373] Fix | Delete
'readonly' => true,
[374] Fix | Delete
),
[375] Fix | Delete
'name' => array(
[376] Fix | Delete
'description' => __( 'Product name.', 'woocommerce' ),
[377] Fix | Delete
'type' => 'string',
[378] Fix | Delete
'context' => array( 'view', 'edit' ),
[379] Fix | Delete
'readonly' => true,
[380] Fix | Delete
),
[381] Fix | Delete
'sku' => array(
[382] Fix | Delete
'description' => __( 'Unique identifier.', 'woocommerce' ),
[383] Fix | Delete
'type' => 'string',
[384] Fix | Delete
'context' => array( 'view', 'edit' ),
[385] Fix | Delete
'readonly' => true,
[386] Fix | Delete
),
[387] Fix | Delete
'stock_status' => array(
[388] Fix | Delete
'description' => __( 'Stock status.', 'woocommerce' ),
[389] Fix | Delete
'type' => 'string',
[390] Fix | Delete
'enum' => array_keys( wc_get_product_stock_status_options() ),
[391] Fix | Delete
'context' => array( 'view', 'edit' ),
[392] Fix | Delete
'readonly' => true,
[393] Fix | Delete
),
[394] Fix | Delete
'stock_quantity' => array(
[395] Fix | Delete
'description' => __( 'Stock quantity.', 'woocommerce' ),
[396] Fix | Delete
'type' => 'integer',
[397] Fix | Delete
'context' => array( 'view', 'edit' ),
[398] Fix | Delete
'readonly' => true,
[399] Fix | Delete
),
[400] Fix | Delete
'manage_stock' => array(
[401] Fix | Delete
'description' => __( 'Manage stock.', 'woocommerce' ),
[402] Fix | Delete
'type' => 'boolean',
[403] Fix | Delete
'context' => array( 'view', 'edit' ),
[404] Fix | Delete
'readonly' => true,
[405] Fix | Delete
),
[406] Fix | Delete
),
[407] Fix | Delete
);
[408] Fix | Delete
[409] Fix | Delete
return $this->add_additional_fields_schema( $schema );
[410] Fix | Delete
}
[411] Fix | Delete
[412] Fix | Delete
/**
[413] Fix | Delete
* Get the query params for collections.
[414] Fix | Delete
*
[415] Fix | Delete
* @return array
[416] Fix | Delete
*/
[417] Fix | Delete
public function get_collection_params() {
[418] Fix | Delete
$params = parent::get_collection_params();
[419] Fix | Delete
unset( $params['after'], $params['before'], $params['force_cache_refresh'] );
[420] Fix | Delete
$params['exclude'] = array(
[421] Fix | Delete
'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
[422] Fix | Delete
'type' => 'array',
[423] Fix | Delete
'items' => array(
[424] Fix | Delete
'type' => 'integer',
[425] Fix | Delete
),
[426] Fix | Delete
'default' => array(),
[427] Fix | Delete
'sanitize_callback' => 'wp_parse_id_list',
[428] Fix | Delete
);
[429] Fix | Delete
$params['include'] = array(
[430] Fix | Delete
'description' => __( 'Limit result set to specific ids.', 'woocommerce' ),
[431] Fix | Delete
'type' => 'array',
[432] Fix | Delete
'items' => array(
[433] Fix | Delete
'type' => 'integer',
[434] Fix | Delete
),
[435] Fix | Delete
'default' => array(),
[436] Fix | Delete
'sanitize_callback' => 'wp_parse_id_list',
[437] Fix | Delete
);
[438] Fix | Delete
$params['offset'] = array(
[439] Fix | Delete
'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ),
[440] Fix | Delete
'type' => 'integer',
[441] Fix | Delete
'sanitize_callback' => 'absint',
[442] Fix | Delete
'validate_callback' => 'rest_validate_request_arg',
[443] Fix | Delete
);
[444] Fix | Delete
$params['order']['default'] = 'asc';
[445] Fix | Delete
$params['orderby']['default'] = 'stock_status';
[446] Fix | Delete
$params['orderby']['enum'] = $this->apply_custom_orderby_filters(
[447] Fix | Delete
array(
[448] Fix | Delete
'stock_status',
[449] Fix | Delete
'stock_quantity',
[450] Fix | Delete
'date',
[451] Fix | Delete
'id',
[452] Fix | Delete
'include',
[453] Fix | Delete
'title',
[454] Fix | Delete
'sku',
[455] Fix | Delete
)
[456] Fix | Delete
);
[457] Fix | Delete
$params['parent'] = array(
[458] Fix | Delete
'description' => __( 'Limit result set to those of particular parent IDs.', 'woocommerce' ),
[459] Fix | Delete
'type' => 'array',
[460] Fix | Delete
'items' => array(
[461] Fix | Delete
'type' => 'integer',
[462] Fix | Delete
),
[463] Fix | Delete
'sanitize_callback' => 'wp_parse_id_list',
[464] Fix | Delete
'default' => array(),
[465] Fix | Delete
);
[466] Fix | Delete
$params['parent_exclude'] = array(
[467] Fix | Delete
'description' => __( 'Limit result set to all items except those of a particular parent ID.', 'woocommerce' ),
[468] Fix | Delete
'type' => 'array',
[469] Fix | Delete
'items' => array(
[470] Fix | Delete
'type' => 'integer',
[471] Fix | Delete
),
[472] Fix | Delete
'sanitize_callback' => 'wp_parse_id_list',
[473] Fix | Delete
'default' => array(),
[474] Fix | Delete
);
[475] Fix | Delete
$params['type'] = array(
[476] Fix | Delete
'description' => __( 'Limit result set to items assigned a stock report type.', 'woocommerce' ),
[477] Fix | Delete
'type' => 'string',
[478] Fix | Delete
'default' => 'all',
[479] Fix | Delete
'enum' => array_merge( array( 'all', 'lowstock' ), array_keys( wc_get_product_stock_status_options() ) ),
[480] Fix | Delete
);
[481] Fix | Delete
[482] Fix | Delete
return $params;
[483] Fix | Delete
}
[484] Fix | Delete
[485] Fix | Delete
/**
[486] Fix | Delete
* Get the column names for export.
[487] Fix | Delete
*
[488] Fix | Delete
* @return array Key value pair of Column ID => Label.
[489] Fix | Delete
*/
[490] Fix | Delete
public function get_export_columns() {
[491] Fix | Delete
$export_columns = array(
[492] Fix | Delete
'title' => __( 'Product / Variation', 'woocommerce' ),
[493] Fix | Delete
'sku' => __( 'SKU', 'woocommerce' ),
[494] Fix | Delete
'stock_status' => __( 'Status', 'woocommerce' ),
[495] Fix | Delete
'stock_quantity' => __( 'Stock', 'woocommerce' ),
[496] Fix | Delete
);
[497] Fix | Delete
[498] Fix | Delete
/**
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function