From 0d756deb1cd28a67aaea84abb0e2f31370523d74 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Wed, 5 Oct 2016 12:27:06 -0300 Subject: [PATCH] [REST API] Allow filter order note by type --- .../class-wc-rest-order-notes-controller.php | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/includes/api/class-wc-rest-order-notes-controller.php b/includes/api/class-wc-rest-order-notes-controller.php index 4de802869cf..835d79e6f0f 100644 --- a/includes/api/class-wc-rest-order-notes-controller.php +++ b/includes/api/class-wc-rest-order-notes-controller.php @@ -170,6 +170,24 @@ class WC_REST_Order_Notes_Controller extends WC_REST_Controller { 'type' => 'order_note', ); + // Allow filter by order note type. + if ( 'customer' === $request['type'] ) { + $args['meta_query'] = array( + array( + 'key' => 'is_customer_note', + 'value' => 1, + 'compare' => '=', + ), + ); + } elseif ( 'internal' === $request['type'] ) { + $args['meta_query'] = array( + array( + 'key' => 'is_customer_note', + 'compare' => 'NOT EXISTS', + ), + ); + } + remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 ); $notes = get_comments( $args ); @@ -411,8 +429,17 @@ class WC_REST_Order_Notes_Controller extends WC_REST_Controller { * @return array */ public function get_collection_params() { - return array( - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), + $params = array(); + $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); + $params['type'] = array( + 'default' => 'any', + 'description' => __( 'Limit result to customers or internal notes.', 'woocommerce' ), + 'type' => 'string', + 'enum' => array( 'any', 'customer', 'internal' ), + 'sanitize_callback' => 'sanitize_key', + 'validate_callback' => 'rest_validate_request_arg', ); + + return $params; } }