Product Gallery: reset main image when variations are cleared (#42830)

* Product Gallery: reset main image when variations are cleared

* Add changelog for woo core

* Update event name to be more descriptive
This commit is contained in:
Roy Ho 2023-12-15 13:22:10 -08:00 committed by GitHub
parent 1bf35ac737
commit d15bfd2398
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 0 deletions

View File

@ -109,8 +109,24 @@ const productGallery = {
attributes: true,
} );
const clearVariationsLink = document.querySelector(
'.wp-block-add-to-cart-form .reset_variations'
);
const selectFirstImage = () => {
context.selectedImage = context.firstMainImageId;
};
if ( clearVariationsLink ) {
clearVariationsLink.addEventListener(
'click',
selectFirstImage
);
}
return () => {
observer.disconnect();
document.removeEventListener( 'click', selectFirstImage );
};
},
keyboardAccess: () => {

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev
Comment: Reset main image when variations are cleared.

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev
Comment: Reset main image when variations are cleared.