[REST API] Allow filter order note by type

This commit is contained in:
Claudio Sanches 2016-10-05 12:27:06 -03:00
parent 36797a382a
commit 0d756deb1c
1 changed files with 29 additions and 2 deletions

View File

@ -170,6 +170,24 @@ class WC_REST_Order_Notes_Controller extends WC_REST_Controller {
'type' => 'order_note', '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 ); remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 );
$notes = get_comments( $args ); $notes = get_comments( $args );
@ -411,8 +429,17 @@ class WC_REST_Order_Notes_Controller extends WC_REST_Controller {
* @return array * @return array
*/ */
public function get_collection_params() { public function get_collection_params() {
return array( $params = array();
'context' => $this->get_context_param( array( 'default' => 'view' ) ), $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;
} }
} }