Remove duplicate notices from cart during ajax updates closes #28914

This commit is contained in:
roykho 2021-03-24 09:59:20 -07:00
parent 7fb346c5d1
commit 9118349520
No known key found for this signature in database
GPG Key ID: 7B36C0EA25795714
1 changed files with 23 additions and 1 deletions

View File

@ -57,6 +57,28 @@ jQuery( function( $ ) {
$node.removeClass( 'processing' ).unblock();
};
/**
* Removes duplicate notices.
*
* @param {JQuery Object} notices
*/
var remove_duplicate_notices = function( notices ) {
var seen = [];
var new_notices = notices;
notices.each( function( index ) {
var text = $( this ).text();
if ( 'undefined' === typeof seen[ text ] ) {
seen[ text ] = true;
} else {
new_notices.splice( index, 1 );
}
} );
return notices;
};
/**
* Update the .woocommerce div with a string of html.
*
@ -67,7 +89,7 @@ jQuery( function( $ ) {
var $html = $.parseHTML( html_str );
var $new_form = $( '.woocommerce-cart-form', $html );
var $new_totals = $( '.cart_totals', $html );
var $notices = $( '.woocommerce-error, .woocommerce-message, .woocommerce-info', $html );
var $notices = remove_duplicate_notices( $( '.woocommerce-error, .woocommerce-message, .woocommerce-info', $html ) );
// No form, cannot do this.
if ( $( '.woocommerce-cart-form' ).length === 0 ) {