From ca0c5b932420b09f24ff1f2c9c5ece3f002a9e1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Thu, 27 Apr 2023 12:21:58 +0200 Subject: [PATCH] Fix Mini Cart block not respecting Add-to-Cart behaviour attribute when adding the first product --- assets/js/blocks/mini-cart/frontend.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/assets/js/blocks/mini-cart/frontend.ts b/assets/js/blocks/mini-cart/frontend.ts index 79bc9a65ec8..12c79ddd78f 100644 --- a/assets/js/blocks/mini-cart/frontend.ts +++ b/assets/js/blocks/mini-cart/frontend.ts @@ -111,7 +111,7 @@ window.addEventListener( 'load', () => { document.body.removeEventListener( 'wc-blocks_added_to_cart', // eslint-disable-next-line @typescript-eslint/no-use-before-define - openDrawerWithRefresh + funcOnAddToCart ); document.body.removeEventListener( 'wc-blocks_removed_from_cart', @@ -150,12 +150,17 @@ window.addEventListener( 'load', () => { miniCartButton.addEventListener( 'focus', loadScripts ); miniCartButton.addEventListener( 'click', openDrawer ); + const funcOnAddToCart = + miniCartBlock.dataset.addToCartBehaviour === 'open_drawer' + ? openDrawerWithRefresh + : loadContentsWithRefresh; + // There might be more than one Mini Cart block in the page. Make sure // only one opens when adding a product to the cart. if ( i === 0 ) { document.body.addEventListener( 'wc-blocks_added_to_cart', - openDrawerWithRefresh + funcOnAddToCart ); document.body.addEventListener( 'wc-blocks_removed_from_cart',