Merge pull request #7758 from helpforfitness/create_order_with_product_sku
[API] Added products to an order by SKU
This commit is contained in:
commit
79760fa5ea
|
@ -862,8 +862,8 @@ class WC_API_Orders extends WC_API_Resource {
|
||||||
$creating = ( 'create' === $action );
|
$creating = ( 'create' === $action );
|
||||||
|
|
||||||
// product is always required
|
// product is always required
|
||||||
if ( ! isset( $item['product_id'] ) ) {
|
if ( ! isset( $item['product_id'] ) && ! isset( $item['sku'] ) ) {
|
||||||
throw new WC_API_Exception( 'woocommerce_api_invalid_product_id', __( 'Product ID is required', 'woocommerce' ), 400 );
|
throw new WC_API_Exception( 'woocommerce_api_invalid_product_id', __( 'Product ID or SKU is required', 'woocommerce' ), 400 );
|
||||||
}
|
}
|
||||||
|
|
||||||
// when updating, ensure product ID provided matches
|
// when updating, ensure product ID provided matches
|
||||||
|
@ -877,7 +877,12 @@ class WC_API_Orders extends WC_API_Resource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$product = wc_get_product( $item['product_id'] );
|
if ( isset( $item['product_id'] ) ) {
|
||||||
|
$product = wc_get_product( $item['product_id'] );
|
||||||
|
} elseif ( isset( $item['sku'] ) ) {
|
||||||
|
$product_id = wc_get_product_id_by_sku( $item['sku'] );
|
||||||
|
$product = wc_get_product( $product_id );
|
||||||
|
}
|
||||||
|
|
||||||
// must be a valid WC_Product
|
// must be a valid WC_Product
|
||||||
if ( ! is_object( $product ) ) {
|
if ( ! is_object( $product ) ) {
|
||||||
|
|
Loading…
Reference in New Issue