woocommerce-paypal-payments/modules/ppcp-settings/resources/js/switchSettingsUi.js

35 lines
739 B
JavaScript
Raw Normal View History

document.addEventListener( 'DOMContentLoaded', () => {
const config = ppcpSwitchSettingsUi;
const button = document.querySelector(
'.button.button-settings-switch-ui'
);
2024-11-20 20:16:35 +04:00
if ( ! typeof config || ! button ) {
return;
}
2024-11-20 20:16:35 +04:00
button.addEventListener( 'click', () => {
fetch( config.endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify( {
nonce: config.nonce,
} ),
} )
.then( ( response ) => {
if ( ! response.ok ) {
throw new Error( 'Network response was not ok' );
}
return response.json();
} )
.then( ( data ) => {
window.location.reload();
} )
.catch( ( error ) => {
console.error( 'Error:', error );
} );
} );
} );