![](/img/trans.png)
[英]Hooking After Validation but Before Order Create in Woocommerce Checkout
[英]WooCommerce Phone Number Validation Before Place Order
我正在嘗試以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;
}
}
使用此代碼,我認為它將正常工作。 謝謝
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);
}
return $phone;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.