[Product Block Editor]: exclude the current product from the suggested ones to use in the Linked Product tab (#43662)

* exclude the current product from the suggested list

* changelog
This commit is contained in:
Damián Suárez 2024-01-16 10:05:04 -03:00 committed by GitHub
parent dc0fd26917
commit ea3504b372
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: add
[Product Block Editor]: exclude the current product from the suggested ones to use in the Linked Product tab

View File

@ -98,7 +98,12 @@ export function LinkedProductListBlockEdit( {
const filter = useCallback(
( search = '' ) => {
return searchProductsDispatcher( linkedProductIds ?? [], search );
// Exclude the current product and any already linked products.
const exclude = [ productId ];
if ( linkedProductIds ) {
exclude.push( ...linkedProductIds );
}
return searchProductsDispatcher( exclude, search );
},
[ linkedProductIds ]
);