From a00d2c4cc219d33b9eb0a946c92aefefb335a3b8 Mon Sep 17 00:00:00 2001 From: inpsyde-maticluznar Date: Thu, 3 Oct 2024 12:48:45 +0200 Subject: [PATCH] Move notices under header and implement close click --- resources/js/mollie-settings-2024.js | 11 +++ src/Assets/AssetsModule.php | 21 ++++++ src/Settings/Page/Section/Notices.php | 101 ++++++++++++++++++-------- webpack.config.js | 3 +- 4 files changed, 106 insertions(+), 30 deletions(-) create mode 100644 resources/js/mollie-settings-2024.js diff --git a/resources/js/mollie-settings-2024.js b/resources/js/mollie-settings-2024.js new file mode 100644 index 00000000..659f2f5d --- /dev/null +++ b/resources/js/mollie-settings-2024.js @@ -0,0 +1,11 @@ +document.addEventListener('DOMContentLoaded', function () { + const noticeCancelButtons = document.querySelectorAll('.mollie-notice button'); + if (noticeCancelButtons.length === 0) { + return; + } + noticeCancelButtons.forEach((button) => { + button.addEventListener('click', function(){ + button.parentNode.remove(); + }); + }) +}); diff --git a/src/Assets/AssetsModule.php b/src/Assets/AssetsModule.php index eb32faf3..467162f9 100644 --- a/src/Assets/AssetsModule.php +++ b/src/Assets/AssetsModule.php @@ -640,9 +640,30 @@ function () use ($container, $hasBlocksEnabled, $pluginVersion, $dataService, $p true ); + wp_register_script( + 'mollie_wc_settings_2024', + $this->getPluginUrl( + $pluginUrl, + '/public/js/mollie-settings-2024.min.js' + ), + ['underscore', 'jquery'], + $pluginVersion, + true + ); + $this->enqueueMollieSettings(); $this->enqueueIconSettings($current_section); } } ); } + + protected function enqueueMollieSettings(){ + $uri = isset($_SERVER['REQUEST_URI']) ? wc_clean( + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + wp_unslash($_SERVER['REQUEST_URI']) + ) : ''; + if (is_string($uri) && strpos($uri, 'tab=mollie_settings')) { + wp_enqueue_script('mollie_wc_settings_2024'); + } + } } diff --git a/src/Settings/Page/Section/Notices.php b/src/Settings/Page/Section/Notices.php index 7c49b11e..11484f1a 100644 --- a/src/Settings/Page/Section/Notices.php +++ b/src/Settings/Page/Section/Notices.php @@ -25,10 +25,10 @@ protected function content(): string ob_start(); ?>
- warnAboutRequiredCheckoutFieldForBillie(); // WPCS: XSS ok.?> - warnAboutRequiredCheckoutFieldForKlarna(); // WPCS: XSS ok.?> - warnMollieBankTransferNotBACS(); // WPCS: XSS ok.?> - warnDirectDebitStatus(); // WPCS: XSS ok.?> + warnAboutRequiredCheckoutFieldForBillie(); // WPCS: XSS ok. ?> + warnAboutRequiredCheckoutFieldForKlarna(); // WPCS: XSS ok. ?> + warnMollieBankTransferNotBACS(); // WPCS: XSS ok. ?> + warnDirectDebitStatus(); // WPCS: XSS ok. ?>
paymentMethods["directdebit"]->getProperty('enabled') !== false; $isSepaEnabled = !$hasCustomSepaSettings || $this->paymentMethods["directdebit"]->getProperty( - 'enabled' - ) === 'yes'; + 'enabled' + ) === 'yes'; $sepaGatewayAllowed = !empty($this->mollieGateways["mollie_wc_gateway_directdebit"]); if (!($sepaGatewayAllowed && !$isSepaEnabled)) { return ''; } return $this->notice( - __( - "You have WooCommerce Subscriptions activated, but not SEPA Direct Debit. Enable SEPA Direct Debit if you want to allow customers to pay subscriptions with iDEAL and/or other 'first' payment methods.", - 'mollie-payments-for-woocommerce' - ) + __( + "You have WooCommerce Subscriptions activated, but not SEPA Direct Debit. Enable SEPA Direct Debit if you want to allow customers to pay subscriptions with iDEAL and/or other 'first' payment methods.", + 'mollie-payments-for-woocommerce' + ) ); } @@ -63,10 +63,10 @@ protected function warnAboutRequiredCheckoutFieldForBillie(): string return ''; } return $this->notice( - __( - 'You have activated Billie. To accept payments, please make sure all default WooCommerce checkout fields are enabled and required. The billing company field is required as well. Make sure to enable the billing company field in the WooCommerce settings if you are using Woocommerce blocks.', - 'mollie-payments-for-woocommerce' - ) + __( + 'You have activated Billie. To accept payments, please make sure all default WooCommerce checkout fields are enabled and required. The billing company field is required as well. Make sure to enable the billing company field in the WooCommerce settings if you are using Woocommerce blocks.', + 'mollie-payments-for-woocommerce' + ) ); } @@ -76,17 +76,17 @@ protected function warnAboutRequiredCheckoutFieldForKlarna(): string return ''; } return $this->notice( - sprintf( + sprintf( /* translators: Placeholder 1: Opening link tag. Placeholder 2: Closing link tag. Placeholder 3: Opening link tag. Placeholder 4: Closing link tag. */ - __( - 'You have activated Klarna. To accept payments, please make sure all default WooCommerce checkout fields are enabled and required. For more information, go to %1$sKlarna Pay Later documentation%2$s or %3$sKlarna Slice it documentation%4$s', - 'mollie-payments-for-woocommerce' - ), - '', - '', - '', - '' - ) + __( + 'You have activated Klarna. To accept payments, please make sure all default WooCommerce checkout fields are enabled and required. For more information, go to %1$sKlarna Pay Later documentation%2$s or %3$sKlarna Slice it documentation%4$s', + 'mollie-payments-for-woocommerce' + ), + '', + '', + '', + '' + ) ); } @@ -98,10 +98,10 @@ protected function warnMollieBankTransferNotBACS(): string } return $this->notice( - __( - 'You have the WooCommerce default Direct Bank Transfer (BACS) payment gateway enabled in WooCommerce. Mollie strongly advices only using Bank Transfer via Mollie and disabling the default WooCommerce BACS payment gateway to prevent possible conflicts.', - 'mollie-payments-for-woocommerce' - ) + __( + 'You have the WooCommerce default Direct Bank Transfer (BACS) payment gateway enabled in WooCommerce. Mollie strongly advices only using Bank Transfer via Mollie and disabling the default WooCommerce BACS payment gateway to prevent possible conflicts.', + 'mollie-payments-for-woocommerce' + ) ); } @@ -129,9 +129,10 @@ protected function isKlarnaEnabled(): bool protected function notice(string $message) { + //notice-warning is-dismissible ob_start(); ?> -
+

[ @@ -140,8 +141,50 @@ protected function notice(string $message) ], ]); ?>

+
+ +