Add filters for place order button mode and text replacement script

This commit is contained in:
Alex P 2023-11-15 09:44:26 +02:00
parent b2ba72c06c
commit c71e312f18
No known key found for this signature in database
GPG key ID: 54487A734A204D71
7 changed files with 240 additions and 0 deletions

View file

@ -0,0 +1,45 @@
import {
getCurrentPaymentMethod,
ORDER_BUTTON_SELECTOR,
PaymentMethods
} from "../Helper/CheckoutMethodState";
class PlaceOrderButtonBootstrap {
constructor(config) {
this.config = config;
this.defaultButtonText = null;
}
init() {
jQuery(document.body).on('updated_checkout payment_method_selected', () => {
this.updateUi();
});
this.updateUi();
}
updateUi() {
const button = document.querySelector(ORDER_BUTTON_SELECTOR);
if (!button) {
return;
}
if (!this.defaultButtonText) {
this.defaultButtonText = button.innerText;
if (!this.defaultButtonText) {
return;
}
}
const currentPaymentMethod = getCurrentPaymentMethod();
if ([PaymentMethods.PAYPAL, PaymentMethods.CARD_BUTTON].includes(currentPaymentMethod)) {
button.innerText = this.config.buttonText;
} else {
button.innerText = this.defaultButtonText;
}
}
}
export default PlaceOrderButtonBootstrap

View file

@ -0,0 +1,8 @@
import PlaceOrderButtonBootstrap from "./modules/ContextBootstrap/PlaceOrderButtonBootstrap";
document.addEventListener(
'DOMContentLoaded',
() => {
const placeOrderButtonBootstrap = new PlaceOrderButtonBootstrap(PpcpPlaceOrderButton);
placeOrderButtonBootstrap.init();
});