WordPress at Your Fingertips
function is not described

WC_API_Products::get_product_by_sku() public WC 2.3.0

Deprecated from version 2.4.0. It is no longer supported and can be removed in future releases. It is recommended to replace this function with the same one.

Get product by SKU

{} It's a method of the class: WC_API_Products{}

No Hooks.

Return

Array|WP_Error.

Usage

$WC_API_Products = new WC_API_Products();
$WC_API_Products->get_product_by_sku( $sku, $fields );
$sku(int) (required)
the product SKU
$fields(string)
-
Default: null

Changelog

Since 2.3.0 Introduced.
Deprecated 2.4.0

Code of WC_API_Products::get_product_by_sku() WC 5.7.1

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() ) );
	}
}