Use order notes for comments

This commit is contained in:
Almira Krdzic
2018-08-26 17:23:33 +02:00
committed by GotPPay
parent bd1d8f2103
commit 54e6495795
6 changed files with 88 additions and 33 deletions

View File

@@ -18,8 +18,19 @@ class Wiaas_Order {
add_filter('woocommerce_rest_prepare_shop_order_object', array(__CLASS__, 'transform_rest_order'), 999, 3);
add_filter('woocommerce_rest_orders_prepare_object_query', array( __CLASS__, 'wiaas_prepare_rest_orders_query'), 10, 2);
add_filter('woocommerce_new_order_note_data', array( __CLASS__, 'update_new_order_comment_date'), 10, 3);
}
public static function update_new_order_comment_date($comment_data, $order_data) {
$user = wp_get_current_user();
$comment_data['comment_author'] = $user->display_name;
$comment_data['comment_author_email'] = $user->user_email;
return $comment_data;
}
/**
* Assignees order to corresponding user organization when order is created.
*
@@ -94,6 +105,8 @@ class Wiaas_Order {
$data = self::_append_commercial_lead_info($data, $order, $request);
$data = self::_append_wiaas_order_details($data, $order, $request);
$data = self::_append_order_comments($data, $order, $request);
$response->set_data($data);
@@ -229,6 +242,34 @@ class Wiaas_Order {
return $data;
}
/** Append order comments if single order is requested
* @param $data
* @param $order
* @param $request
*/
private static function _append_order_comments($data, $order, $request) {
if (isset($request['id'])) {
$current_user = wp_get_current_user();
$comments = $order->get_customer_order_notes();
$data['comments'] = array();
foreach ($comments as $comment) {
$data['comments'][] = array(
'id' => $comment->comment_ID,
'content' => $comment->comment_content,
'username' => $comment->comment_author,
'date' => $comment->comment_date,
'is_owner' => $comment->comment_author === $current_user->display_name,
);
}
}
return $data;
}
}
Wiaas_Order::init();