wc_format_phone_number()WC 1.0

Formats the phone number by replacing the character . with -.

No Hooks.

Returns

String. Formatted phone number.

Usage

$phone = wc_format_phone_number( $phone );
$phone(string) (required)
Phone number.

Examples

0

#1 Formatting a phone number in Woocommerce

$phone = '8.928.123.45.67';
echo wc_format_phone_number( $phone ); //> 8-928-123-45-67

wc_format_phone_number() code WC 10.3.3

function wc_format_phone_number( $phone ) {
	$phone = $phone ?? '';

	if ( ! WC_Validation::is_phone( $phone ) ) {
		return '';
	}
	return preg_replace( '/[^0-9\+\-\(\)\s]/', '-', preg_replace( '/[\x00-\x1F\x7F-\xFF]/', '', $phone ) );
}