Merge pull request #993 from woocommerce/PCP-965-update-default-settings-for-pay-pal-buttons-and-pay-later-messaging

Update button defaults & setting descriptions
This commit is contained in:
Narek Zakarian 2022-11-18 18:37:32 +04:00 committed by GitHub
commit 769699763d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 122 additions and 77 deletions

View file

@ -92,10 +92,20 @@ import {setVisibleByClass, isVisible} from "../../../ppcp-button/resources/js/mo
renderPreview(settingsCallback, render);
}
function shouldShowPayLaterButton() {
const payLaterButtonLocations = document.querySelector('[name="ppcp[pay_later_button_locations][]"]');
if(!payLaterButtonInput || !payLaterButtonLocations) {
return PayPalCommerceGatewaySettings.is_pay_later_button_enabled
}
return payLaterButtonInput.checked && payLaterButtonLocations.selectedOptions.length > 0
}
function getPaypalScriptSettings() {
const disableFundingInput = jQuery('[name="ppcp[disable_funding][]"]');
let disabledSources = disableFundingInput.length > 0 ? disableFundingInput.val() : PayPalCommerceGatewaySettings.disabled_sources;
const isPayLaterButtonEnabled = payLaterButtonInput ? payLaterButtonInput.checked : PayPalCommerceGatewaySettings.is_pay_later_button_enabled
const payLaterButtonPreview = jQuery('#ppcpPayLaterButtonPreview');
const settings = {
'client-id': PayPalCommerceGatewaySettings.client_id,
'currency': PayPalCommerceGatewaySettings.currency,
@ -105,7 +115,11 @@ import {setVisibleByClass, isVisible} from "../../../ppcp-button/resources/js/mo
'buyer-country': PayPalCommerceGatewaySettings.country,
};
if (!isPayLaterButtonEnabled) {
if(payLaterButtonPreview?.length) {
disabledSources = Object.keys(PayPalCommerceGatewaySettings.all_funding_sources);
}
if (!shouldShowPayLaterButton()) {
disabledSources = disabledSources.concat('credit')
}
@ -231,8 +245,6 @@ import {setVisibleByClass, isVisible} from "../../../ppcp-button/resources/js/mo
};
}
const payLaterMessagingLocations = ['product', 'cart', 'checkout', 'general'];
const previewElements = document.querySelectorAll('.ppcp-preview');
if (previewElements.length) {
let oldScriptSettings = getPaypalScriptSettings();
@ -249,35 +261,27 @@ import {setVisibleByClass, isVisible} from "../../../ppcp-button/resources/js/mo
}, 1000));
loadPaypalScript(oldScriptSettings, () => {
createButtonPreview(() => getButtonSettings('#ppcpCheckoutButtonPreview', {
'color': '#ppcp-button_color',
'shape': '#ppcp-button_shape',
'label': '#ppcp-button_label',
'tagline': '#ppcp-button_tagline',
'layout': '#ppcp-button_layout',
}));
createButtonPreview(() => getButtonSettings('#ppcpProductButtonPreview', {
'color': '#ppcp-button_product_color',
'shape': '#ppcp-button_product_shape',
'label': '#ppcp-button_product_label',
'tagline': '#ppcp-button_product_tagline',
'layout': '#ppcp-button_product_layout',
}));
createButtonPreview(() => getButtonSettings('#ppcpCartButtonPreview', {
'color': '#ppcp-button_cart_color',
'shape': '#ppcp-button_cart_shape',
'label': '#ppcp-button_cart_label',
'tagline': '#ppcp-button_cart_tagline',
'layout': '#ppcp-button_cart_layout',
}));
createButtonPreview(() => getButtonSettings('#ppcpMiniCartButtonPreview', {
'color': '#ppcp-button_mini-cart_color',
'shape': '#ppcp-button_mini-cart_shape',
'label': '#ppcp-button_mini-cart_label',
'tagline': '#ppcp-button_mini-cart_tagline',
'layout': '#ppcp-button_mini-cart_layout',
'height': '#ppcp-button_mini-cart_height',
}));
const payLaterMessagingLocations = ['product', 'cart', 'checkout', 'general'];
const paypalButtonLocations = ['product', 'cart', 'checkout', 'mini-cart'];
paypalButtonLocations.forEach((location) => {
const inputNamePrefix = location === 'checkout' ? '#ppcp-button' : '#ppcp-button_' + location;
let wrapperName = location.charAt(0).toUpperCase() + location.slice(1);
const fields = {
'color': inputNamePrefix + '_color',
'shape': inputNamePrefix + '_shape',
'label': inputNamePrefix + '_label',
'tagline': inputNamePrefix + '_tagline',
'layout': inputNamePrefix + '_layout',
}
if (location === 'mini-cart') {
fields['height'] = inputNamePrefix + '_height';
wrapperName = 'MiniCart';
}
createButtonPreview(() => getButtonSettings('#ppcp' + wrapperName + 'ButtonPreview', fields));
});
payLaterMessagingLocations.forEach((location) => {
const inputNamePrefix = '#ppcp-pay_later_' + location + '_message';