54 lines
1.1 KiB
PHP
54 lines
1.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Class Wiaas_Order
|
|
*
|
|
* Integrates Woocommerce order with Wiaas order
|
|
*/
|
|
|
|
class Wiaas_Order {
|
|
|
|
public static function init() {
|
|
add_filter('woocommerce_rest_prepare_shop_order_object', array(__CLASS__, 'transform_rest_order'), 10, 3);
|
|
}
|
|
|
|
/**
|
|
* Apply wiaas custome tranformation on retrieved JSON order object
|
|
*
|
|
* @param $response
|
|
* @param $order
|
|
* @param $request
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public static function transform_rest_order($response, $order, $request) {
|
|
$data = $response->get_data();
|
|
|
|
# apply overrides
|
|
$data = self::_append_order_process($data, $order, $request);
|
|
|
|
$response->set_data($data);
|
|
|
|
return $response;
|
|
}
|
|
|
|
/**
|
|
* Append order delivery process info if single order is requested
|
|
* @param $data
|
|
* @param $order
|
|
* @param $request
|
|
*
|
|
* @return mixed
|
|
*/
|
|
private static function _append_order_process($data, $order, $request) {
|
|
|
|
# if this is response to `/order/[id]`
|
|
if (isset($request['id'])) {
|
|
$data['delivery-process'] = Wiaas_Delivery_Process::get_order_delivery_process($order->get_id());
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
}
|
|
|
|
Wiaas_Order::init(); |