Merge pull request #1770 from woocommerce/PCP-798-paylater-locations

Improve Pay Later messages and add Shop, Home locations
This commit is contained in:
Emili Castells 2023-10-17 12:03:42 +02:00 committed by GitHub
commit 814c9fcd36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 474 additions and 75 deletions

View file

@ -156,8 +156,15 @@ class CheckoutBootstap {
}
shouldShowMessages() {
return getCurrentPaymentMethod() === PaymentMethods.PAYPAL
&& !PayPalCommerceGateway.is_free_trial_cart;
// hide when another method selected only if messages are near buttons
const messagesWrapper = document.querySelector(this.gateway.messages.wrapper);
if (getCurrentPaymentMethod() !== PaymentMethods.PAYPAL &&
messagesWrapper && jQuery(messagesWrapper).closest('.ppc-button-wrapper').length
) {
return false;
}
return !PayPalCommerceGateway.is_free_trial_cart;
}
disableCreditCardFields() {

View file

@ -28,15 +28,9 @@ class MessageRenderer {
return;
}
const newWrapper = document.createElement('div');
newWrapper.setAttribute('id', this.config.wrapper.replace('#', ''));
const wrapper = document.querySelector(this.config.wrapper);
this.currentNumber++;
newWrapper.setAttribute('data-render-number', this.currentNumber);
const oldWrapper = document.querySelector(this.config.wrapper);
const sibling = oldWrapper.nextSibling;
oldWrapper.parentElement.removeChild(oldWrapper);
sibling.parentElement.insertBefore(newWrapper, sibling);
wrapper.setAttribute('data-render-number', this.currentNumber);
widgetBuilder.registerMessages(this.config.wrapper, options);
widgetBuilder.renderMessages(this.config.wrapper);

View file

@ -84,11 +84,14 @@ class WidgetBuilder {
return;
}
const entry = this.messages.get(wrapper);
if (this.hasRendered(wrapper)) {
const element = document.querySelector(wrapper);
element.setAttribute('data-pp-amount', entry.options.amount);
return;
}
const entry = this.messages.get(wrapper);
const btn = this.paypal.Messages(entry.options);
btn.render(entry.wrapper);