From b6860866207a0d34e17edf09803d8dbfee9a8f87 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Tue, 17 Oct 2023 17:44:11 +0200 Subject: [PATCH 1/2] Add details to customer email --- src/Gateway/MolliePaymentGateway.php | 43 ++++++++++++++++++---------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/Gateway/MolliePaymentGateway.php b/src/Gateway/MolliePaymentGateway.php index f71438a8..d45d98e9 100644 --- a/src/Gateway/MolliePaymentGateway.php +++ b/src/Gateway/MolliePaymentGateway.php @@ -30,7 +30,8 @@ class MolliePaymentGateway extends WC_Payment_Gateway implements MolliePaymentGa /** * @var bool */ - protected static $alreadyDisplayedInstructions = false; + protected static $alreadyDisplayedAdminInstructions = false; + protected static $alreadyDisplayedCustomerInstructions = false; /** * Recurring total, zero does not define a recurring total * @@ -115,7 +116,7 @@ public function __construct( $this->paymentFactory = $paymentFactory; $this->pluginId = $pluginId; - // No plugin id, gateway id is unique enough + // No plugin id, gateway id is unique enough $this->plugin_id = ''; // Use gateway class name as gateway id $this->gatewayId(); @@ -156,6 +157,12 @@ public function __construct( 10, 3 ); + add_action( + 'woocommerce_email_order_meta', + [$this, 'displayInstructions'], + 10, + 3 + ); // Adjust title and text on Order Received page in some cases, see issue #166 add_filter('the_title', [$this, 'onOrderReceivedTitle'], 10, 2); @@ -267,17 +274,17 @@ public function isValidForUse(): bool $test_mode = $this->dataService->isTestModeEnabled(); $this->errors[] = ($test_mode ? __( - 'Test mode enabled.', - 'mollie-payments-for-woocommerce' - ) . ' ' : '') . sprintf( + 'Test mode enabled.', + 'mollie-payments-for-woocommerce' + ) . ' ' : '') . sprintf( /* translators: The surrounding %s's Will be replaced by a link to the global setting page */ - __( - 'No API key provided. Please %1$sset you Mollie API key%2$s first.', - 'mollie-payments-for-woocommerce' - ), - '', - '' - ); + __( + 'No API key provided. Please %1$sset you Mollie API key%2$s first.', + 'mollie-payments-for-woocommerce' + ), + '', + '' + ); return false; } @@ -806,8 +813,9 @@ public function displayInstructions( $admin_instructions = false, $plain_text = false ) { - - if (!$this::$alreadyDisplayedInstructions) { + if (($admin_instructions && !$this::$alreadyDisplayedAdminInstructions) + || (!$admin_instructions && !$this::$alreadyDisplayedCustomerInstructions) + ) { $order_payment_method = $order->get_payment_method(); // Invalid gateway @@ -846,7 +854,12 @@ public function displayInstructions( } } } - $this::$alreadyDisplayedInstructions = true; + if ($admin_instructions && !$this::$alreadyDisplayedAdminInstructions) { + $this::$alreadyDisplayedAdminInstructions = true; + } + if (!$admin_instructions && !$this::$alreadyDisplayedCustomerInstructions) { + $this::$alreadyDisplayedCustomerInstructions = true; + } } /** From 257ce096734f136be41202351daac430521e7d81 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Tue, 24 Oct 2023 11:07:40 +0200 Subject: [PATCH 2/2] Fix CS --- src/Gateway/MolliePaymentGateway.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Gateway/MolliePaymentGateway.php b/src/Gateway/MolliePaymentGateway.php index d45d98e9..7cf669eb 100644 --- a/src/Gateway/MolliePaymentGateway.php +++ b/src/Gateway/MolliePaymentGateway.php @@ -274,17 +274,17 @@ public function isValidForUse(): bool $test_mode = $this->dataService->isTestModeEnabled(); $this->errors[] = ($test_mode ? __( - 'Test mode enabled.', - 'mollie-payments-for-woocommerce' - ) . ' ' : '') . sprintf( + 'Test mode enabled.', + 'mollie-payments-for-woocommerce' + ) . ' ' : '') . sprintf( /* translators: The surrounding %s's Will be replaced by a link to the global setting page */ - __( - 'No API key provided. Please %1$sset you Mollie API key%2$s first.', - 'mollie-payments-for-woocommerce' - ), - '', - '' - ); + __( + 'No API key provided. Please %1$sset you Mollie API key%2$s first.', + 'mollie-payments-for-woocommerce' + ), + '', + '' + ); return false; } @@ -813,7 +813,9 @@ public function displayInstructions( $admin_instructions = false, $plain_text = false ) { - if (($admin_instructions && !$this::$alreadyDisplayedAdminInstructions) + + if ( + ($admin_instructions && !$this::$alreadyDisplayedAdminInstructions) || (!$admin_instructions && !$this::$alreadyDisplayedCustomerInstructions) ) { $order_payment_method = $order->get_payment_method();