Delivery setup
This commit is contained in:
54
backend/app/plugins/wiaas/includes/class-wiaas-order.php
Normal file
54
backend/app/plugins/wiaas/includes/class-wiaas-order.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?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();
|
||||
Reference in New Issue
Block a user