Warning: This method has been deprecated.
WC_API_Products::get_product_by_sku( int $sku, string $fields = null )
Get product by SKU
Description Description
Parameters Parameters
- $sku
-
(Required) the product SKU
- $fields
-
(Optional)
Default value: null
Return Return
(array|WP_Error)
Source Source
File: includes/legacy/api/v2/class-wc-api-products.php
public function get_product_by_sku( $sku, $fields = null ) {
try {
$id = wc_get_product_id_by_sku( $sku );
if ( empty( $id ) ) {
throw new WC_API_Exception( 'woocommerce_api_invalid_product_sku', __( 'Invalid product SKU', 'woocommerce' ), 404 );
}
return $this->get_product( $id, $fields );
} catch ( WC_API_Exception $e ) {
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
}
}
Changelog Changelog
| Version | Description |
|---|---|
| 2.4.0 | This method has been deprecated. |
| 2.3.0 | Introduced. |