wc_make_phone_clickable()WC 3.1.0

Convert plaintext phone number to clickable phone number.

Remove formatting and allow "+". Example and specs: https://developer.mozilla.org/en/docs/Web/HTML/Element/a#Creating_a_phone_link

No Hooks.

Return

String. Content with converted phone number.

Usage

wc_make_phone_clickable( $phone );
$phone(string) (required)
Content to convert phone number.

Changelog

Since 3.1.0 Introduced.

wc_make_phone_clickable() code WC 8.7.0

function wc_make_phone_clickable( $phone ) {
	$number = trim( preg_replace( '/[^\d|\+]/', '', $phone ) );

	return $number ? '<a href="tel:' . esc_attr( $number ) . '">' . esc_html( $phone ) . '</a>' : '';
}