From ed62fa73f8eb36032112acba6e883921a44aeead Mon Sep 17 00:00:00 2001 From: "admin@knitpay.org" Date: Tue, 12 Nov 2024 00:43:02 +0530 Subject: [PATCH] Check UPI Address pattern only if UPI address is shown and required. Fixes: https://wordpress.org/support/topic/warning-undefined-array-key-customer_upiwc_address/ --- includes/class-payment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-payment.php b/includes/class-payment.php index 972663a..e814394 100644 --- a/includes/class-payment.php +++ b/includes/class-payment.php @@ -513,7 +513,7 @@ public function validate_fields() { if ( $this->upi_address === 'show_handle' ) { $regex = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*$/i'; } - if ( ! preg_match( $regex, sanitize_text_field( $_POST['customer_upiwc_address'] ) ) && in_array( $this->upi_address, [ 'show', 'show_handle' ] ) && $this->require_upi === 'yes' ) { + if ( in_array( $this->upi_address, [ 'show', 'show_handle' ] ) && $this->require_upi === 'yes' &&! preg_match( $regex, sanitize_text_field( $_POST['customer_upiwc_address'] ) ) ) { wc_add_notice( __( 'Please enter a valid UPI Address!', 'upi-qr-code-payment-for-woocommerce' ), 'error' ); return false; }