Prices.php
28 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\Rest\Wrapper\Orders; |
| 4 | |
| 5 | use WCML\Orders\Helper as OrdersHelper; |
| 6 | use WPML\FP\Obj; |
| 7 | use WCML\Rest\Wrapper\Handler; |
| 8 | use WCML\Rest\Exceptions\InvalidCurrency; |
| 9 | |
| 10 | class Prices extends Handler { |
| 11 | |
| 12 | public function insert( $object, $request, $creating ) { |
| 13 | |
| 14 | $currency = Obj::prop( 'currency', $request->get_params() ); |
| 15 | |
| 16 | if ( $currency ) { |
| 17 | |
| 18 | $orderId = $object->get_id(); |
| 19 | $currencies = get_woocommerce_currencies(); |
| 20 | |
| 21 | if ( ! isset( $currencies[ $currency ] ) ) { |
| 22 | throw new InvalidCurrency( $currency ); |
| 23 | } |
| 24 | |
| 25 | OrdersHelper::setCurrency( $orderId, $currency ); |
| 26 | } |
| 27 | } |
| 28 | } |