Cherry pick 51449 into release/9.3 (#51476)
* Check if button element exists when triggering added_to_cart (#51449) * Prep for cherry pick 51449 --------- Co-authored-by: Sam Seay <samueljseay@gmail.com> Co-authored-by: WooCommerce Bot <no-reply@woocommerce.com>
This commit is contained in:
parent
68812a9c59
commit
589367e156
|
@ -173,6 +173,8 @@ jQuery( function( $ ) {
|
|||
* Update cart page elements after add to cart events.
|
||||
*/
|
||||
AddToCartHandler.prototype.updateButton = function( e, fragments, cart_hash, $button ) {
|
||||
// Some themes and plugins manually trigger added_to_cart without passing a button element, which in turn calls this function.
|
||||
// If there is no button we don't want to crash.
|
||||
$button = typeof $button === 'undefined' ? false : $button;
|
||||
|
||||
if ( $button ) {
|
||||
|
@ -222,6 +224,11 @@ jQuery( function( $ ) {
|
|||
* Update cart live region message after add/remove cart events.
|
||||
*/
|
||||
AddToCartHandler.prototype.alertCartUpdated = function( e, fragments, cart_hash, $button ) {
|
||||
// Some themes and plugins manually trigger added_to_cart without passing a button element, which in turn calls this function.
|
||||
// If there is no button we don't want to crash.
|
||||
$button = typeof $button === 'undefined' ? false : $button;
|
||||
|
||||
if ( $button ) {
|
||||
var message = $button.data( 'success_message' );
|
||||
|
||||
if ( !message ) {
|
||||
|
@ -235,6 +242,7 @@ jQuery( function( $ ) {
|
|||
.delay(1000)
|
||||
.text( message )
|
||||
.attr( 'aria-relevant', 'all' );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue