Added sku filter to the /products endpoint. 

Will let you search for products by sku without using the
/products/sku/<sku> endpoint. Its now possible to search for product
skus with specialchars like / and -.
This commit is contained in:
nils-fredrik@maksimer.no 2015-03-21 18:53:00 +01:00
parent 17fb3874e6
commit 686c40919b
1 changed files with 12 additions and 0 deletions

View File

@ -520,6 +520,18 @@ class WC_API_Products extends WC_API_Resource {
$query_args['product_cat'] = $args['category'];
}
// filter by specific sku
if( ! empty( $args['sku'] ) ) {
if(!is_array($query_args['meta_query'])) {
$query_args['meta_query'] = array();
}
$query_args['meta_query'][] = array(
'key' => '_sku',
'value' => $args['sku'],
'compare' => "="
);
}
$query_args = $this->merge_query_args( $query_args, $args );
return new WP_Query( $query_args );