【发布时间】:2018-10-07 04:35:16
【问题描述】:
我正在尝试将客户的电话号码转换为 921234456 格式。
这是我在functions.php中的代码
// Format phone number in this format: 923131234567
add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');
function my_custom_checkout_field_process() {
global $woocommerce;
/**
*Format phone number in this format: 923131234567
* If no country code is provided, by default 92 (Pakistan) country code is added.
* @param $phone
* @return string
*/
$phone = $_POST['billing_phone']
function formatPhoneNumber($phone]) {
$phone = trim($phone);
$phone = str_replace([' ','-','_'],'',$phone);
if(empty($phone)) {
return NULL;
}
$phone = ltrim(ltrim($phone, '0'),'+');
if(strlen($phone) <= 11) {
$phone = '92' . ltrim($phone,0);
}
return $phone;
}
}
【问题讨论】:
标签: php wordpress woocommerce checkout orders