From f82b0be0e4ee76c73b183f8cec479388a9b67edf Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Thu, 22 Feb 2024 19:21:24 +0400 Subject: [PATCH] Put messaging configurator on top of the page --- .../resources/js/paylater-configurator.js | 10 ++- .../Settings/Fields/pay-later-tab-fields.php | 89 +++++++++---------- 2 files changed, 53 insertions(+), 46 deletions(-) diff --git a/modules/ppcp-paylater-configurator/resources/js/paylater-configurator.js b/modules/ppcp-paylater-configurator/resources/js/paylater-configurator.js index fc78ef4f6..7250e8ce0 100644 --- a/modules/ppcp-paylater-configurator/resources/js/paylater-configurator.js +++ b/modules/ppcp-paylater-configurator/resources/js/paylater-configurator.js @@ -1,10 +1,18 @@ document.addEventListener( 'DOMContentLoaded', () => { const form = document.querySelector('#mainform'); const table = form.querySelector('.form-table'); + const headingRow = table.querySelector('#field-pay_later_messaging_heading'); const saveChangesButton = form.querySelector('.woocommerce-save-button'); const publishButtonClassName = PcpPayLaterConfigurator.publishButtonClassName; - table.insertAdjacentHTML('afterend', '
'); + const tempContainer = document.createElement('div'); + tempContainer.innerHTML = `
`; + + // Get the new row element from the container + const newRow = tempContainer.firstChild; + + // Insert the new row after the headingRow + headingRow.parentNode.insertBefore(newRow, headingRow.nextSibling); saveChangesButton.addEventListener('click', () => { diff --git a/modules/ppcp-wc-gateway/src/Settings/Fields/pay-later-tab-fields.php b/modules/ppcp-wc-gateway/src/Settings/Fields/pay-later-tab-fields.php index 094e12026..5285ca39c 100644 --- a/modules/ppcp-wc-gateway/src/Settings/Fields/pay-later-tab-fields.php +++ b/modules/ppcp-wc-gateway/src/Settings/Fields/pay-later-tab-fields.php @@ -44,51 +44,6 @@ return function ( ContainerInterface $container, array $fields ): array { }; $pay_later_fields = array( - 'pay_later_button_heading' => array( - 'heading' => __( 'Pay Later Button', 'woocommerce-paypal-payments' ), - 'type' => 'ppcp-heading', - 'screens' => array( State::STATE_ONBOARDED ), - 'requirements' => array( 'messages' ), - 'gateway' => Settings::PAY_LATER_TAB_ID, - 'description' => sprintf( - // translators: %1$s and %2$s are the opening and closing of HTML tag. - __( 'When enabled, a %1$sPay Later button%2$s is displayed for eligible customers.%3$sPayPal buttons must be enabled to display the Pay Later button.', 'woocommerce-paypal-payments' ), - '', - '', - '' - ), - ), - 'pay_later_button_enabled' => array( - 'title' => __( 'Enable/Disable', 'woocommerce-paypal-payments' ), - 'type' => 'checkbox', - 'label' => esc_html( $pay_later_messaging_enabled_label ), - 'default' => true, - 'screens' => array( State::STATE_ONBOARDED ), - 'requirements' => array( 'messages' ), - 'gateway' => Settings::PAY_LATER_TAB_ID, - 'input_class' => $vault_enabled ? array( 'ppcp-disabled-checkbox' ) : array(), - ), - 'pay_later_button_locations' => array( - 'title' => __( 'Pay Later Button Locations', 'woocommerce-paypal-payments' ), - 'type' => 'ppcp-multiselect', - 'class' => array(), - 'input_class' => array( 'wc-enhanced-select' ), - 'default' => $container->get( 'wcgateway.settings.pay-later.default-button-locations' ), - 'desc_tip' => false, - 'description' => __( 'Select where the Pay Later button should be displayed.', 'woocommerce-paypal-payments' ), - 'options' => $container->get( 'wcgateway.settings.pay-later.button-locations' ), - 'screens' => array( State::STATE_ONBOARDED ), - 'requirements' => array( 'messages' ), - 'gateway' => Settings::PAY_LATER_TAB_ID, - ), - 'pay_later_button_preview' => array( - 'type' => 'ppcp-text', - 'text' => $render_preview_element( 'ppcpPayLaterButtonPreview', 'button', $button_message ), - 'screens' => array( State::STATE_ONBOARDED ), - 'requirements' => array( 'messages' ), - 'gateway' => Settings::PAY_LATER_TAB_ID, - ), - // Messaging. 'pay_later_messaging_heading' => array( 'heading' => __( 'Pay Later Messaging', 'woocommerce-paypal-payments' ), @@ -871,6 +826,50 @@ return function ( ContainerInterface $container, array $fields ): array { 'requirements' => array( 'messages' ), 'gateway' => Settings::PAY_LATER_TAB_ID, ), + 'pay_later_button_heading' => array( + 'heading' => __( 'Pay Later Button', 'woocommerce-paypal-payments' ), + 'type' => 'ppcp-heading', + 'screens' => array( State::STATE_ONBOARDED ), + 'requirements' => array( 'messages' ), + 'gateway' => Settings::PAY_LATER_TAB_ID, + 'description' => sprintf( + // translators: %1$s and %2$s are the opening and closing of HTML tag. + __( 'When enabled, a %1$sPay Later button%2$s is displayed for eligible customers.%3$sPayPal buttons must be enabled to display the Pay Later button.', 'woocommerce-paypal-payments' ), + '', + '', + '' + ), + ), + 'pay_later_button_enabled' => array( + 'title' => __( 'Enable/Disable', 'woocommerce-paypal-payments' ), + 'type' => 'checkbox', + 'label' => esc_html( $pay_later_messaging_enabled_label ), + 'default' => true, + 'screens' => array( State::STATE_ONBOARDED ), + 'requirements' => array( 'messages' ), + 'gateway' => Settings::PAY_LATER_TAB_ID, + 'input_class' => $vault_enabled ? array( 'ppcp-disabled-checkbox' ) : array(), + ), + 'pay_later_button_locations' => array( + 'title' => __( 'Pay Later Button Locations', 'woocommerce-paypal-payments' ), + 'type' => 'ppcp-multiselect', + 'class' => array(), + 'input_class' => array( 'wc-enhanced-select' ), + 'default' => $container->get( 'wcgateway.settings.pay-later.default-button-locations' ), + 'desc_tip' => false, + 'description' => __( 'Select where the Pay Later button should be displayed.', 'woocommerce-paypal-payments' ), + 'options' => $container->get( 'wcgateway.settings.pay-later.button-locations' ), + 'screens' => array( State::STATE_ONBOARDED ), + 'requirements' => array( 'messages' ), + 'gateway' => Settings::PAY_LATER_TAB_ID, + ), + 'pay_later_button_preview' => array( + 'type' => 'ppcp-text', + 'text' => $render_preview_element( 'ppcpPayLaterButtonPreview', 'button', $button_message ), + 'screens' => array( State::STATE_ONBOARDED ), + 'requirements' => array( 'messages' ), + 'gateway' => Settings::PAY_LATER_TAB_ID, + ), ); return array_merge( $fields, $pay_later_fields );