Use MutationObserver to detect order button visibility changes

Such as for the old PayPal plugin,
which shows it on click + with some animation,
or Conditional WooCommerce Checkout Field,
which shows the button after loading some data
This commit is contained in:
Alex P 2021-11-11 18:03:50 +02:00
parent 3dc9b48e1b
commit 9c7859bf35

View file

@ -10,6 +10,10 @@ class CheckoutBootstap {
this.spinner = spinner;
this.standardOrderButtonSelector = '#place_order';
this.buttonChangeObserver = new MutationObserver((el) => {
this.updateUi();
});
}
init() {
@ -64,6 +68,11 @@ class CheckoutBootstap {
this.gateway.hosted_fields.wrapper,
actionHandler.configuration(),
);
this.buttonChangeObserver.observe(
document.querySelector(this.standardOrderButtonSelector),
{attributes: true}
);
}
updateUi() {