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
This commit is contained in:
Nathan Silveira 2024-09-18 15:26:40 -03:00 committed by GitHub
parent 9d135ee2f5
commit 96719139be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Add global_unique_id parameter to products REST API

View File

@ -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.