我要求woocommerce中的结算电话与电子邮件一样有效。每当我们想要在具有相同电子邮件ID的woocommerce中创建帐户时,它就会抛出错误电子邮件已经存在。我想在结算手机中使用相同的功能。
答案 0 :(得分:0)
这将是您的解决方案:
add_filter('woocommerce_new_customer_data', 'risbl_custom_customer_data', 10 );
function risbl_custom_customer_data() {
global $wpdb;
$billing_phone = $_POST['billing_phone'];
$results = $wpdb->get_results('select * from `wp_usermeta` where meta_key = "billing_phone" and meta_value = "'.$billing_phone.'"');
if ( $results ) {
wc_add_notice( __( 'Phone number already exists.' ), 'error' );
}
}
答案 1 :(得分:0)
试试这个:
function wc_validate_phone_number() {
$phone = (isset( $_POST['billing_phone'] ) ? trim(
$_POST['billing_phone'] ) : '');
if ( ! preg_match( '/\(?([0-9]{3})\)?([ .-]?)([0-9]{3})\2([0-9]{4})/',
$phone ) ) {
wc_add_notice( __( 'Invalid Phone Number. Please enter with a valid
phone number. Eg: (123) 456 7890' ), 'error' );
}
}
答案 2 :(得分:0)
这对我有用 用您的表名更改wp_usermeta
add_action( 'woocommerce_register_form', 'wooc_extra_register_fields' );
function wooc_validate_extra_register_fields( $username, $email, $validation_errors ) {
global $wpdb;
$billing_phone =$_POST['billing_phone'];
if ( isset( $_POST['billing_first_name'] ) && empty( $_POST['billing_first_name'] ) ) {
$validation_errors->add( 'billing_first_name_error', __( ' First name is required!', 'woocommerce' ) );
}
if ( isset( $_POST['billing_last_name'] ) && empty( $_POST['billing_last_name'] ) ) {
$validation_errors->add( 'billing_last_name_error', __( ' Last name is required!.', 'woocommerce' ) );
}
if ( isset($billing_phone ) && empty( $billing_phone ) ) {
$validation_errors->add( 'billing_phone_error', __( ' Prone is required!.', 'woocommerce' ) );
}
$results = $wpdb->get_results('select * from `wp_usermeta` where meta_key = "billing_phone" and meta_value = "'.$billing_phone.'"');
if ( $results ) {
$validation_errors->add( 'billing_phone_error', __( 'Phone number already exists..', 'woocommerce' ) );
}
return $validation_errors;
}