| @@ 775-803 (lines=29) @@ | ||
| 772 | throw new WC_REST_Exception( 'woocommerce_rest_invalid_coupon_total', __( 'Coupon discount must be a positive amount.', 'woocommerce' ), 400 ); |
|
| 773 | } |
|
| 774 | ||
| 775 | if ( 'create' === $action ) { |
|
| 776 | // Coupon code is required. |
|
| 777 | if ( empty( $coupon['code'] ) ) { |
|
| 778 | throw new WC_REST_Exception( 'woocommerce_rest_invalid_coupon_coupon', __( 'Coupon code is required.', 'woocommerce' ), 400 ); |
|
| 779 | } |
|
| 780 | ||
| 781 | $coupon_id = $order->add_coupon( $coupon['code'], floatval( $coupon['discount'] ) ); |
|
| 782 | ||
| 783 | if ( ! $coupon_id ) { |
|
| 784 | throw new WC_REST_Exception( 'woocommerce_rest_cannot_create_order_coupon', __( 'Cannot create coupon, try again.', 'woocommerce' ), 500 ); |
|
| 785 | } |
|
| 786 | ||
| 787 | } else { |
|
| 788 | $coupon_args = array(); |
|
| 789 | ||
| 790 | if ( isset( $coupon['code'] ) ) { |
|
| 791 | $coupon_args['code'] = $coupon['code']; |
|
| 792 | } |
|
| 793 | ||
| 794 | if ( isset( $coupon['discount'] ) ) { |
|
| 795 | $coupon_args['discount_amount'] = floatval( $coupon['discount'] ); |
|
| 796 | } |
|
| 797 | ||
| 798 | $coupon_id = $order->update_coupon( $coupon['id'], $coupon_args ); |
|
| 799 | ||
| 800 | if ( ! $coupon_id ) { |
|
| 801 | throw new WC_REST_Exception( 'woocommerce_rest_cannot_update_order_coupon', __( 'Cannot update coupon, try again.', 'woocommerce' ), 500 ); |
|
| 802 | } |
|
| 803 | } |
|
| 804 | } |
|
| 805 | ||
| 806 | /** |
|
| @@ 1217-1247 (lines=31) @@ | ||
| 1214 | throw new WC_CLI_Exception( 'woocommerce_invalid_coupon_total', __( 'Coupon discount total must be a positive amount', 'woocommerce' ) ); |
|
| 1215 | } |
|
| 1216 | ||
| 1217 | if ( 'create' === $action ) { |
|
| 1218 | ||
| 1219 | // coupon code is required |
|
| 1220 | if ( empty( $coupon['code'] ) ) { |
|
| 1221 | throw new WC_CLI_Exception( 'woocommerce_invalid_coupon_coupon', __( 'Coupon code is required', 'woocommerce' ) ); |
|
| 1222 | } |
|
| 1223 | ||
| 1224 | $coupon_id = $order->add_coupon( $coupon['code'], isset( $coupon['amount'] ) ? floatval( $coupon['amount'] ) : 0 ); |
|
| 1225 | ||
| 1226 | if ( ! $coupon_id ) { |
|
| 1227 | throw new WC_CLI_Exception( 'woocommerce_cannot_create_order_coupon', __( 'Cannot create coupon, try again', 'woocommerce' ) ); |
|
| 1228 | } |
|
| 1229 | ||
| 1230 | } else { |
|
| 1231 | ||
| 1232 | $coupon_args = array(); |
|
| 1233 | ||
| 1234 | if ( isset( $coupon['code'] ) ) { |
|
| 1235 | $coupon_args['code'] = $coupon['code']; |
|
| 1236 | } |
|
| 1237 | ||
| 1238 | if ( isset( $coupon['amount'] ) ) { |
|
| 1239 | $coupon_args['discount_amount'] = floatval( $coupon['amount'] ); |
|
| 1240 | } |
|
| 1241 | ||
| 1242 | $coupon_id = $order->update_coupon( $coupon['id'], $coupon_args ); |
|
| 1243 | ||
| 1244 | if ( ! $coupon_id ) { |
|
| 1245 | throw new WC_CLI_Exception( 'woocommerce_cannot_update_order_coupon', __( 'Cannot update coupon, try again', 'woocommerce' ) ); |
|
| 1246 | } |
|
| 1247 | } |
|
| 1248 | } |
|
| 1249 | } |
|
| 1250 | ||