wc_format_phone_number()WC 1.0

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

Hooks from the function

Returns

String. Formatted phone number.

Usage

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

Examples

1

#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 11.0.0

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

	$is_valid  = WC_Validation::is_phone_format( $original );
	$formatted = $is_valid
		? (string) preg_replace( '/[^0-9\+\-\(\)\s]/', '-', preg_replace( '/[\x00-\x1F\x7F-\xFF]/', '', $original ) )
		: '';

	/**
	 * Filters the formatted phone number.
	 *
	 * @since 11.0.0
	 *
	 * @param string $formatted The formatted phone number, or an empty string if $original isn't a valid phone number.
	 * @param string $original  The phone number passed to the function.
	 * @param bool   $is_valid  Whether $original passed the default phone number validation.
	 */
	return apply_filters( 'woocommerce_format_phone_number', $formatted, $original, $is_valid );
}