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

Fix Mini Cart block not respecting Add-to-Cart behaviour attribute when adding the first product #9257

Merged
merged 1 commit into from
May 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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