WC_REST_Orders_V2_Controller::get_product_id
Gets the product ID from the SKU or posted ID.
Метод класса: WC_REST_Orders_V2_Controller{}
Хуков нет.
Возвращает
int.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_product_id( $posted, $action );
- $posted(массив) (обязательный)
- Request data.
- $action(строка)
'create'to add line item or'update'to update it.
По умолчанию:'create'
Код WC_REST_Orders_V2_Controller::get_product_id() WC REST Orders V2 Controller::get product id WC 11.2.1
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;
}