From e9d20c9f6658494f583d575a2d2bb503f185641a Mon Sep 17 00:00:00 2001 From: Guillermo Gette Date: Thu, 12 Mar 2015 22:52:37 +1100 Subject: [PATCH] update set_line_item to let you set items by sku --- includes/api/class-wc-api-orders.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/includes/api/class-wc-api-orders.php b/includes/api/class-wc-api-orders.php index 2b4a94ee137..995521e9d3b 100644 --- a/includes/api/class-wc-api-orders.php +++ b/includes/api/class-wc-api-orders.php @@ -846,8 +846,8 @@ class WC_API_Orders extends WC_API_Resource { $creating = ( 'create' === $action ); // product is always required - if ( ! isset( $item['product_id'] ) ) { - throw new WC_API_Exception( 'woocommerce_api_invalid_product_id', __( 'Product ID is required', 'woocommerce' ), 400 ); + if ( ! isset( $item['product_id'] ) && ! isset( $item['sku'] ) ) { + 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 @@ -861,7 +861,11 @@ 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 = wc_get_product_by_sku( $item['sku'] ); + } // must be a valid WC_Product if ( ! is_object( $product ) ) {