Merge remote-tracking branch 'origin/trunk' into PCP-3790-Prevent-plugin-use-for-Send-only-countries

# Conflicts:
#	modules/ppcp-wc-gateway/src/WCGatewayModule.php
This commit is contained in:
inpsyde-maticluznar 2024-10-30 06:38:01 +01:00
commit 5ff581a934
No known key found for this signature in database
GPG key ID: D005973F231309F6
148 changed files with 17164 additions and 409 deletions

View file

@ -1,3 +1,8 @@
import {
setVisible,
setVisibleByClass,
} from '../../../ppcp-button/resources/js/modules/Helper/Hiding';
document.addEventListener( 'DOMContentLoaded', () => {
const payLaterMessagingSelectableLocations = [
'product',
@ -216,6 +221,18 @@ document.addEventListener( 'DOMContentLoaded', () => {
replace();
};
const hideElements = ( selectorGroup ) => {
selectorGroup.forEach( ( selector ) =>
setVisibleByClass( selector, false, 'hide' )
);
};
const showElements = ( selectorGroup ) => {
selectorGroup.forEach( ( selector ) =>
setVisibleByClass( selector, true, 'hide' )
);
};
const toggleInputsBySelectedLocations = (
stylingPerSelector,
locationsSelector,
@ -226,30 +243,30 @@ document.addEventListener( 'DOMContentLoaded', () => {
const payLaterMessagingEnabled = document.querySelector(
payLaterMessagingEnabledSelector
);
const stylingPerElement = document.querySelector( stylingPerSelector );
const locationsElement = document.querySelector( locationsSelector );
const stylingPerElementWrapper = stylingPerElement?.closest( 'tr' );
const stylingPerElementWrapperSelector =
'#' + stylingPerElementWrapper?.getAttribute( 'id' );
const stylingPerElement = document.querySelector( stylingPerSelector );
if ( ! stylingPerElement ) {
return;
}
const stylingPerElementWrapper = stylingPerElement.closest( 'tr' );
const toggleElementsBySelectedLocations = () => {
stylingPerElementWrapper.style.display = '';
const selectedLocations = getSelectedLocations( locationsSelector );
const emptySmartButtonLocationMessage = jQuery(
'.ppcp-empty-smart-button-location'
setVisibleByClass(
stylingPerElementWrapper,
selectedLocations.length > 0,
'hide'
);
if ( selectedLocations.length === 0 ) {
hideElements(
groupToHideOnChecked.concat(
stylingPerElementWrapperSelector
)
hideElements( groupToHideOnChecked );
const emptySmartButtonLocationMessage = document.querySelector(
'.ppcp-empty-smart-button-location'
);
if ( emptySmartButtonLocationMessage.length === 0 ) {
if ( ! emptySmartButtonLocationMessage ) {
jQuery(
PayPalCommerceSettings.empty_smart_button_location_message
).insertAfter(
@ -277,11 +294,11 @@ document.addEventListener( 'DOMContentLoaded', () => {
);
groupToShowOnChecked.forEach( ( element ) => {
if ( inputSelectors.includes( element ) ) {
document.querySelector( element ).style.display = '';
return;
}
document.querySelector( element ).style.display = 'none';
setVisibleByClass(
element,
inputSelectors.includes( element ),
'hide'
);
} );
if ( inputType === 'messages' ) {
@ -289,18 +306,6 @@ document.addEventListener( 'DOMContentLoaded', () => {
}
};
const hideElements = ( selectroGroup ) => {
selectroGroup.forEach( ( elementToHide ) => {
document.querySelector( elementToHide ).style.display = 'none';
} );
};
const showElements = ( selectroGroup ) => {
selectroGroup.forEach( ( elementToShow ) => {
document.querySelector( elementToShow ).style.display = '';
} );
};
groupToggle( stylingPerSelector, groupToShowOnChecked );
toggleElementsBySelectedLocations();
@ -327,7 +332,7 @@ document.addEventListener( 'DOMContentLoaded', () => {
} );
// We need to use jQuery here as the select might be a select2 element, which doesn't use native events.
jQuery( locationsElement ).on( 'change', function () {
jQuery( locationsSelector ).on( 'change', function () {
const emptySmartButtonLocationMessage = jQuery(
'.ppcp-empty-smart-button-location'
);
@ -457,6 +462,38 @@ document.addEventListener( 'DOMContentLoaded', () => {
}
};
/**
* Hide the subscription settings when smart buttons are disabled for checkout,
* since the basic redirect gateway is disabled for subscriptions.
*/
const initSettingsHidingForPlaceOrderGateway = () => {
const selectors = [
'#field-paypal_saved_payments',
'#field-subscriptions_mode',
'#field-vault_enabled',
];
const updateSettingsVisibility = () => {
const selectedLocations = getSelectedLocations(
smartButtonLocationsSelect
);
const hasCheckoutSmartButtons =
selectedLocations.includes( 'checkout' ) ||
selectedLocations.includes( 'checkout-block-express' );
selectors.forEach( ( selector ) => {
setVisibleByClass( selector, hasCheckoutSmartButtons, 'hide' );
} );
};
updateSettingsVisibility();
jQuery( smartButtonLocationsSelect ).on(
'change',
updateSettingsVisibility
);
};
( () => {
removeDisabledCardIcons(
'select[name="ppcp[disable_cards][]"]',
@ -488,6 +525,8 @@ document.addEventListener( 'DOMContentLoaded', () => {
toggleMessagingEnabled();
initSettingsHidingForPlaceOrderGateway();
groupToggle( '#ppcp-vault_enabled', [
'#field-subscription_behavior_when_vault_fails',
] );

View file

@ -117,7 +117,7 @@ class OnboardingAssets {
array(
'empty_smart_button_location_message' => sprintf(
'<p class="description ppcp-empty-smart-button-location">%1$s</p>',
__( 'Note: If no button location is selected, the PayPal gateway will not be available.', 'woocommerce-paypal-payments' )
__( 'Note: PayPal buttons and advanced payment features (Alternative Payment Methods, Subscriptions, etc.) are unavailable if no Smart Button Location is configured.', 'woocommerce-paypal-payments' )
),
)
);