Update the JS logic to also work with new note

This commit is contained in:
Narek Zakarian 2025-08-15 20:33:18 +04:00
parent 628c83b7b9
commit 1179a17ae3
No known key found for this signature in database
GPG key ID: 07AFD7E7A9C164A7

View file

@ -1,11 +1,7 @@
document.addEventListener( 'DOMContentLoaded', () => {
const config = ppcpSwitchSettingsUi;
const button = document.querySelector(
'.button.button-settings-switch-ui'
);
const link = document.querySelector( 'a.settings-switch-ui' );
if ( typeof config === 'undefined' || ( ! button && ! link ) ) {
if ( typeof config === 'undefined' ) {
return;
}
@ -34,18 +30,21 @@ document.addEventListener( 'DOMContentLoaded', () => {
return response.json();
} )
.then( ( data ) => {
window.location.reload();
window.location.href = config.settingsUrl;
} )
.catch( ( error ) => {
console.error( 'Error:', error );
} );
};
if ( button ) {
button.addEventListener( 'click', handleClick );
}
if ( link ) {
link.addEventListener( 'click', handleClick );
}
document.addEventListener( 'click', ( event ) => {
if (
event.target.closest( '.button.button-settings-switch-ui' ) ||
event.target.closest( 'a.settings-switch-ui' ) ||
event.target.closest( 'a[name="settings-switch-ui"]' ) ||
event.target.closest( '.woocommerce-inbox-note__action-button' )
) {
handleClick( event );
}
} );
} );