mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 12:25:15 +08:00
Add filters for place order button mode and text replacement script
This commit is contained in:
parent
b2ba72c06c
commit
c71e312f18
7 changed files with 240 additions and 0 deletions
|
@ -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
|
8
modules/ppcp-button/resources/js/place-order-button.js
Normal file
8
modules/ppcp-button/resources/js/place-order-button.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
import PlaceOrderButtonBootstrap from "./modules/ContextBootstrap/PlaceOrderButtonBootstrap";
|
||||
|
||||
document.addEventListener(
|
||||
'DOMContentLoaded',
|
||||
() => {
|
||||
const placeOrderButtonBootstrap = new PlaceOrderButtonBootstrap(PpcpPlaceOrderButton);
|
||||
placeOrderButtonBootstrap.init();
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue