Conditionally add a message when no location is selected.

This commit is contained in:
Narek Zakarian 2022-12-21 17:08:56 +04:00
parent eb080c9275
commit 5b15b4b3fe
No known key found for this signature in database
GPG key ID: 07AFD7E7A9C164A7
2 changed files with 16 additions and 0 deletions

View file

@ -187,9 +187,13 @@ document.addEventListener(
const toggleElementsBySelectedLocations = () => {
stylingPerElementWrapper.style.display = '';
let selectedLocations = getSelectedLocations(locationsSelector);
let emptySmartButtonLocationMessage = jQuery('.ppcp-empty-smart-button-location');
if(selectedLocations.length === 0) {
hideElements(groupToHideOnChecked.concat(stylingPerElementWrapperSelector));
if (emptySmartButtonLocationMessage.length === 0) {
jQuery(PayPalCommerceGatewaySettings.empty_smart_button_location_message).insertAfter(jQuery(smartButtonLocationsSelector).find('.description'));
}
}
if (! stylingPerElement.checked) {
@ -257,6 +261,8 @@ document.addEventListener(
// 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 (){
let emptySmartButtonLocationMessage = jQuery('.ppcp-empty-smart-button-location');
emptySmartButtonLocationMessage?.remove();
toggleElementsBySelectedLocations()
stylingPerElement.dispatchEvent(new Event('change'))
});

View file

@ -110,6 +110,16 @@ class OnboardingAssets {
$this->version,
true
);
wp_localize_script(
'ppcp-settings',
'PayPalCommerceGatewaySettings',
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' )
),
)
);
$url = untrailingslashit( $this->module_url ) . '/assets/js/onboarding.js';
wp_register_script(