Hide card button in previews when has acdc or separate gateway

This commit is contained in:
Alex P 2023-11-08 09:46:52 +02:00
parent 47728a78ff
commit c72a335cdd
No known key found for this signature in database
GPG key ID: 54487A734A204D71
4 changed files with 33 additions and 3 deletions

View file

@ -96,6 +96,11 @@ document.addEventListener(
renderPreview(settingsCallback, render);
}
function currentTabId() {
const params = new URLSearchParams(location.search);
return params.has('ppcp-tab') ? params.get('ppcp-tab') : params.get('section');
}
function shouldShowPayLaterButton() {
const payLaterButtonLocations = document.querySelector('[name="ppcp[pay_later_button_locations][]"]');
@ -106,6 +111,14 @@ document.addEventListener(
return payLaterButtonInput.checked && payLaterButtonLocations.selectedOptions.length > 0
}
function shouldDisableCardButton() {
if (currentTabId() === 'ppcp-card-button-gateway') {
return false;
}
return PayPalCommerceGatewaySettings.is_acdc_enabled || jQuery('#ppcp-allow_card_button_gateway').is(':checked');
}
function getPaypalScriptSettings() {
const disableFundingInput = jQuery('[name="ppcp[disable_funding][]"]');
let disabledSources = disableFundingInput.length > 0 ? disableFundingInput.val() : PayPalCommerceGatewaySettings.disabled_sources;
@ -130,6 +143,10 @@ document.addEventListener(
disabledSources = disabledSources.concat('credit')
}
if (shouldDisableCardButton()) {
disabledSources = disabledSources.concat('card');
}
if (disabledSources?.length) {
settings['disable-funding'] = disabledSources;
}