| @@ 1215-1245 (lines=31) @@ | ||
| 1212 | throw new WC_CLI_Exception( 'woocommerce_invalid_coupon_total', __( 'Coupon discount total must be a positive amount', 'woocommerce' ) ); |
|
| 1213 | } |
|
| 1214 | ||
| 1215 | if ( 'create' === $action ) { |
|
| 1216 | ||
| 1217 | // coupon code is required |
|
| 1218 | if ( empty( $coupon['code'] ) ) { |
|
| 1219 | throw new WC_CLI_Exception( 'woocommerce_invalid_coupon_coupon', __( 'Coupon code is required', 'woocommerce' ) ); |
|
| 1220 | } |
|
| 1221 | ||
| 1222 | $coupon_id = $order->add_coupon( $coupon['code'], isset( $coupon['amount'] ) ? floatval( $coupon['amount'] ) : 0 ); |
|
| 1223 | ||
| 1224 | if ( ! $coupon_id ) { |
|
| 1225 | throw new WC_CLI_Exception( 'woocommerce_cannot_create_order_coupon', __( 'Cannot create coupon, try again', 'woocommerce' ) ); |
|
| 1226 | } |
|
| 1227 | ||
| 1228 | } else { |
|
| 1229 | ||
| 1230 | $coupon_args = array(); |
|
| 1231 | ||
| 1232 | if ( isset( $coupon['code'] ) ) { |
|
| 1233 | $coupon_args['code'] = $coupon['code']; |
|
| 1234 | } |
|
| 1235 | ||
| 1236 | if ( isset( $coupon['amount'] ) ) { |
|
| 1237 | $coupon_args['discount_amount'] = floatval( $coupon['amount'] ); |
|
| 1238 | } |
|
| 1239 | ||
| 1240 | $coupon_id = $order->update_coupon( $coupon['id'], $coupon_args ); |
|
| 1241 | ||
| 1242 | if ( ! $coupon_id ) { |
|
| 1243 | throw new WC_CLI_Exception( 'woocommerce_cannot_update_order_coupon', __( 'Cannot update coupon, try again', 'woocommerce' ) ); |
|
| 1244 | } |
|
| 1245 | } |
|
| 1246 | } |
|
| 1247 | } |
|
| 1248 | ||
| @@ 1203-1233 (lines=31) @@ | ||
| 1200 | throw new WC_API_Exception( 'woocommerce_invalid_coupon_total', __( 'Coupon discount total must be a positive amount', 'woocommerce' ), 400 ); |
|
| 1201 | } |
|
| 1202 | ||
| 1203 | if ( 'create' === $action ) { |
|
| 1204 | ||
| 1205 | // coupon code is required |
|
| 1206 | if ( empty( $coupon['code'] ) ) { |
|
| 1207 | throw new WC_API_Exception( 'woocommerce_invalid_coupon_coupon', __( 'Coupon code is required', 'woocommerce' ), 400 ); |
|
| 1208 | } |
|
| 1209 | ||
| 1210 | $coupon_id = $order->add_coupon( $coupon['code'], isset( $coupon['amount'] ) ? floatval( $coupon['amount'] ) : 0 ); |
|
| 1211 | ||
| 1212 | if ( ! $coupon_id ) { |
|
| 1213 | throw new WC_API_Exception( 'woocommerce_cannot_create_order_coupon', __( 'Cannot create coupon, try again', 'woocommerce' ), 500 ); |
|
| 1214 | } |
|
| 1215 | ||
| 1216 | } else { |
|
| 1217 | ||
| 1218 | $coupon_args = array(); |
|
| 1219 | ||
| 1220 | if ( isset( $coupon['code'] ) ) { |
|
| 1221 | $coupon_args['code'] = $coupon['code']; |
|
| 1222 | } |
|
| 1223 | ||
| 1224 | if ( isset( $coupon['amount'] ) ) { |
|
| 1225 | $coupon_args['discount_amount'] = floatval( $coupon['amount'] ); |
|
| 1226 | } |
|
| 1227 | ||
| 1228 | $coupon_id = $order->update_coupon( $coupon['id'], $coupon_args ); |
|
| 1229 | ||
| 1230 | if ( ! $coupon_id ) { |
|
| 1231 | throw new WC_API_Exception( 'woocommerce_cannot_update_order_coupon', __( 'Cannot update coupon, try again', 'woocommerce' ), 500 ); |
|
| 1232 | } |
|
| 1233 | } |
|
| 1234 | } |
|
| 1235 | ||
| 1236 | /** |
|