WordPress at Your Fingertips
function is not described

WC_REST_Orders_V2_Controller::get_product_id() protected WC 1.0

Gets the product ID from the SKU or posted ID.

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

No Hooks.

Return

Int.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_product_id( $posted, $action );
$posted(array) (required)
Request data.
$action(string)
'create' to add line item or 'update' to update it.
Default: 'create'

Code of WC_REST_Orders_V2_Controller::get_product_id() WC 5.9.0

protected function get_product_id( $posted, $action = 'create' ) {
	if ( ! empty( $posted['sku'] ) ) {
		$product_id = (int) wc_get_product_id_by_sku( $posted['sku'] );
	} elseif ( ! empty( $posted['product_id'] ) && empty( $posted['variation_id'] ) ) {
		$product_id = (int) $posted['product_id'];
	} elseif ( ! empty( $posted['variation_id'] ) ) {
		$product_id = (int) $posted['variation_id'];
	} elseif ( 'update' === $action ) {
		$product_id = 0;
	} else {
		throw new WC_REST_Exception( 'woocommerce_rest_required_product_reference', __( 'Product ID or SKU is required.', 'woocommerce' ), 400 );
	}
	return $product_id;
}