Remove duplicate notices from cart during ajax updates closes #28914
This commit is contained in:
parent
7fb346c5d1
commit
9118349520
|
@ -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 ) {
|
||||
|
|
Loading…
Reference in New Issue