diff --git a/includes/wc-formatting-functions.php b/includes/wc-formatting-functions.php index 7480d170eba..f0cd54c647e 100644 --- a/includes/wc-formatting-functions.php +++ b/includes/wc-formatting-functions.php @@ -976,7 +976,7 @@ function wc_format_phone_number( $phone ) { if ( ! WC_Validation::is_phone( $phone ) ) { return ''; } - return preg_replace( '/[^0-9\+\-\s]/', '-', preg_replace( '/[\x00-\x1F\x7F-\xFF]/', '', $phone ) ); + return preg_replace( '/[^0-9\+\-\(\)\s]/', '-', preg_replace( '/[\x00-\x1F\x7F-\xFF]/', '', $phone ) ); } /** diff --git a/tests/unit-tests/formatting/functions.php b/tests/unit-tests/formatting/functions.php index cf6253cf11e..a2d9be890fe 100644 --- a/tests/unit-tests/formatting/functions.php +++ b/tests/unit-tests/formatting/functions.php @@ -792,6 +792,7 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case { */ public function test_wc_format_phone_number() { $this->assertEquals( '1-610-385-0000', wc_format_phone_number( '1.610.385.0000' ) ); + $this->assertEquals( '(32) 3212-2345', wc_format_phone_number( '(32) 3212-2345' ) ); // This number contains non-visible unicode chars at the beginning and end of string, which makes it invalid phone number. $this->assertEquals( '', wc_format_phone_number( '‭+47 0000 00003‬' ) ); $this->assertEquals( '27 00 00 0000', wc_format_phone_number( '27 00 00 0000' ) );