diff --git a/plugins/woocommerce/changelog/update-rest-api-global-unique-id b/plugins/woocommerce/changelog/update-rest-api-global-unique-id new file mode 100644 index 00000000000..2a66b917137 --- /dev/null +++ b/plugins/woocommerce/changelog/update-rest-api-global-unique-id @@ -0,0 +1,4 @@ +Significance: minor +Type: add + +Add global_unique_id parameter to products REST API diff --git a/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-products-controller.php b/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-products-controller.php index f1c472a38cd..4e981a84ff0 100644 --- a/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-products-controller.php +++ b/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-products-controller.php @@ -259,6 +259,18 @@ class WC_REST_Products_Controller extends WC_REST_Products_V2_Controller { } } + if ( ! empty( $request['global_unique_id'] ) ) { + $global_unique_ids = array_map( 'trim', explode( ',', $request['global_unique_id'] ) ); + $args['meta_query'] = $this->add_meta_query( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query + $args, + array( + 'key' => '_global_unique_id', + 'value' => $global_unique_ids, + 'compare' => 'IN', + ) + ); + } + // Filter by tax class. if ( ! empty( $request['tax_class'] ) ) { $args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok.