簡體   English   中英

清理電話號碼輸入woocommerce

[英]sanitizing phone number input woocommerce

我需要在woocommerce結帳頁面上屏蔽一些電話號碼

如果電話號碼以0111或0222或0333開頭,則會提示錯誤消息。


默認情況下,WooCommerce結帳字段支持以下字段的屬性

$defaults = array(
'type'              => 'text',
'label'             => '',
'description'       => '',
'placeholder'       => '',
'maxlength'         => false,
'required'          => false,
'id'                => $key,
'class'             => array(),
'label_class'       => array(),
'input_class'       => array(),
'return'            => false,
'options'           => array(),
'custom_attributes' => array(),
'validate'          => array(),
'default'           => '',
);

現在我只能使用以下功能設置“最大長度”數字

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields )
{        
  $fields['billing']['billing_phone']['maxlength'] = 10;      
  return $fields;    
}

您可以嘗試這樣的事情:

add_action('woocommerce_checkout_process', 'phoneValidate');

function phoneValidate() {
    $billing_phone = filter_input(INPUT_POST, 'billing_phone');

    if ( /* you condition */) {
        wc_add_notice(__('Invalid Phone Number.'), 'error');
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM