[API] Created a route to get products by SKU, closes #6847
This commit is contained in:
parent
15996a1dee
commit
553fe744cf
|
@ -66,6 +66,11 @@ class WC_API_Products extends WC_API_Resource {
|
|||
array( array( $this, 'get_product_category' ), WC_API_Server::READABLE ),
|
||||
);
|
||||
|
||||
# GET /products/sku/<product sku>
|
||||
$routes[ $this->base . '/sku/(?P<sku>\w+)' ] = array(
|
||||
array( array( $this, 'get_product_by_sku' ), WC_API_Server::READABLE ),
|
||||
);
|
||||
|
||||
return $routes;
|
||||
}
|
||||
|
||||
|
@ -1808,4 +1813,18 @@ class WC_API_Products extends WC_API_Resource {
|
|||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Get product by SKU
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @param int $sku the product SKU
|
||||
* @param string $fields
|
||||
* @return array
|
||||
*/
|
||||
public function get_product_by_sku( $sku, $fields = null ) {
|
||||
$id = wc_get_product_id_by_sku( $sku );
|
||||
|
||||
return $this->get_product( $id, $fields );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue