Skip to content

Commit

Permalink
Merge pull request woocommerce#15459 from woocommerce/fix/14659
Browse files Browse the repository at this point in the history
Make phone number clickable
  • Loading branch information
mikejolley authored Jun 6, 2017
2 parents bb1c7f0 + 6c42f3c commit c77347d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion includes/admin/meta-boxes/class-wc-meta-box-order-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,13 @@ public static function output( $post ) {
$field_value = $order->get_meta( '_' . $field_name );
}

echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . make_clickable( esc_html( $field_value ) ) . '</p>';
if ( 'billing_phone' === $field_name ) {
$field_value = wc_make_phone_clickable( $field_value );
} else {
$field_value = make_clickable( esc_html( $field_value ) );
}

echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . wp_kses_post( $field_value ) . '</p>';
}

echo '</div>';
Expand Down
17 changes: 17 additions & 0 deletions includes/wc-core-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1629,3 +1629,20 @@ function wc_get_permalink_structure() {
}
return $permalinks;
}

/**
* 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
*
* @since 3.1.0
*
* @param string $phone Content to convert phone number.
* @return string Content with converted phone number.
*/
function wc_make_phone_clickable( $phone ) {
$number = trim( preg_replace( '/[^\d|\+]/', '', $phone ) );

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

0 comments on commit c77347d

Please sign in to comment.