From 96719139beeea1e3d1d87d56143c74efa0313d92 Mon Sep 17 00:00:00 2001 From: Nathan Silveira Date: Wed, 18 Sep 2024 15:26:40 -0300 Subject: [PATCH] Add global_unique_id parameter to products REST API (#51264) * Add global_unique_id parameter to products REST API * Remove unnecessary if statement related to commas and trim request content --- .../changelog/update-rest-api-global-unique-id | 4 ++++ .../Version3/class-wc-rest-products-controller.php | 12 ++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 plugins/woocommerce/changelog/update-rest-api-global-unique-id 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.