Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Fix Mini Cart block not respecting Add-to-Cart behaviour attribute wh…
Browse files Browse the repository at this point in the history
…en adding the first product (#9257)
  • Loading branch information
Aljullu authored May 3, 2023
1 parent 73d631c commit 662d318
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions assets/js/blocks/mini-cart/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 662d318

Please sign in to comment.