Improve `remove_duplicate_notices` which fixes issue 35005 (#40170)
* Fix issue 35005 * Changelog. --------- Co-authored-by: barryhughes <3594411+barryhughes@users.noreply.github.com>
This commit is contained in:
parent
0885808c07
commit
ef36c24858
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
Fixes the logic responsible for removing duplicate notices from the (classic) cart page.
|
|
@ -60,23 +60,22 @@ jQuery( function( $ ) {
|
|||
/**
|
||||
* Removes duplicate notices.
|
||||
*
|
||||
* @param {JQuery Object} notices
|
||||
* @param {JQuery Object} $notices
|
||||
*/
|
||||
var remove_duplicate_notices = function( notices ) {
|
||||
var seen = [];
|
||||
var new_notices = notices;
|
||||
var remove_duplicate_notices = function( $notices ) {
|
||||
var seen = new Set();
|
||||
var deduplicated_notices = [];
|
||||
|
||||
notices.each( function( index ) {
|
||||
var text = $( this ).text();
|
||||
$notices.each( function() {
|
||||
const text = $( this ).text();
|
||||
|
||||
if ( 'undefined' === typeof seen[ text ] ) {
|
||||
seen[ text ] = true;
|
||||
} else {
|
||||
new_notices.splice( index, 1 );
|
||||
if ( ! seen.has( text ) ) {
|
||||
seen.add( text );
|
||||
deduplicated_notices.push( this );
|
||||
}
|
||||
} );
|
||||
|
||||
return new_notices;
|
||||
return $( deduplicated_notices );
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue