Use order notes for comments
This commit is contained in:
@@ -23,6 +23,8 @@ class Wiaas_Delivery_Process {
|
||||
|
||||
add_filter( 'gform_entry_meta', array(__CLASS__, 'extend_gravity_form_entry_meta'), 10, 2 );
|
||||
add_action( 'gravityflow_workflow_complete', array(__CLASS__, 'maybe_complete_parent_process_step'), 5, 3 );
|
||||
|
||||
add_action( 'gravityflow_workflow_complete', array(__CLASS__, 'maybe_complete_parent_order'), 10, 3 );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,6 +36,29 @@ class Wiaas_Delivery_Process {
|
||||
Gravity_Flow_Steps::register( new Wiaas_Delivery_Process_Step() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe complete parent order for completed delivery process
|
||||
* @param $entry_id
|
||||
* @param $form
|
||||
*/
|
||||
public static function maybe_complete_parent_order($entry_id, $form) {
|
||||
$entry = GFAPI::get_entry($entry_id);
|
||||
|
||||
$order_id = $entry['wiaas_delivery_order_id'];
|
||||
|
||||
if (!isset($order_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$process_entry_id = get_post_meta($order_id, 'wiaas_delivery_process_entry_id', true);
|
||||
|
||||
// order process entry completed, so complete order
|
||||
if (absint($process_entry_id) === $entry_id) {
|
||||
$order = wc_get_order($order_id);
|
||||
$order->update_status('completed', 'Completed order delivery process.', true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves delivery process instance for order
|
||||
*
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user