Created
April 17, 2020 09:17
-
-
Save aliaramli/854b08910e5766ecba59360f2b2cbcc3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$malaysia_phone_patterns = "#(^[6]\w*$)|(^[+][6]\w*$)#"; | |
$number = get_usermeta($post_author_id,'billing_phone'); | |
preg_match($malaysia_phone_patterns, $number, $matches); | |
if ($matches) { | |
// full pattern of all. | |
//means one of the pattern is captured | |
if ($matches[0]) { | |
//do nothing. | |
} | |
// first pattern matches with 6 at start | |
if($matches[1]) { | |
//do nothing | |
} | |
if (count($matches)>2) { | |
// second pattern matches with +6 at start | |
if($matches[2]) { | |
//remove the '+' character! | |
$number=str_replace("+", "", $matches[2]); | |
} | |
} | |
} else { | |
//means no +6/6...so add 6 at front. | |
$number = "6".$number; | |
} | |
$whatsapp_number_link = "https://wa.me/".$number; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment