From f9b160b16cfc407ccf498d9e94113c75bbfdc83c Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 13 Jun 2016 11:05:29 -0300 Subject: [PATCH] [REST API] Fixed product search by type, closes #11101 --- includes/api/class-wc-rest-products-controller.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/includes/api/class-wc-rest-products-controller.php b/includes/api/class-wc-rest-products-controller.php index d32f69f56b0..bde4dba4657 100644 --- a/includes/api/class-wc-rest-products-controller.php +++ b/includes/api/class-wc-rest-products-controller.php @@ -129,7 +129,6 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller { // Map between taxonomy name and arg's key. $taxonomies = array( - 'product_type' => 'type', 'product_cat' => 'category', 'product_tag' => 'tag', 'product_shipping_class' => 'shipping_class', @@ -148,6 +147,17 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller { } } + // Filter product type by slug. + if ( ! empty( $request['type'] ) ) { + $terms = explode( ',', $request['type'] ); + + $tax_query[] = array( + 'taxonomy' => 'product_type', + 'field' => 'slug', + 'terms' => $terms, + ); + } + // Filter by attribute and term. if ( ! empty( $request['attribute'] ) && ! empty( $request['attribute_term'] ) ) { if ( in_array( $request['attribute'], wc_get_attribute_taxonomy_names() ) ) {