gpt4 book ai didi

javascript - 如何在 woocommerce 结账页面添加另一个电话字段进行确认

转载 作者:行者123 更新时间:2023-12-03 05:12:13 24 4
gpt4 key购买 nike

enter image description here

嗨,我希望它像图片中那样,如果电话号码不匹配,则不会验证

真的需要帮助,谢谢

最佳答案

这是我对在计费部分添加自定义字段的回答

enter image description here

add_filter( 'woocommerce_checkout_fields' , 'bbloomer_add_field_and_reorder_fields' );

function bbloomer_add_field_and_reorder_fields( $fields ) {

if (!$_POST['shipping_method_tax_exempt']) {
unset($fields['extra_fields']['claimant_name']);
unset($fields['extra_fields']['description_illness']);
unset($fields['extra_fields']['vat_confirm']);
}

// Add New Fields

$fields['billing']['billing_phone_confirm'] = array(
'label' => __('Phone confirm', 'woocommerce'),
'required' => true,
'class' => array('form-row-last'),
'clear' => false
);


/*$fields['shipping']['shipping_houseno'] = array(
'label' => __('House Number', 'woocommerce'),
'placeholder' => _x('House Number', 'placeholder', 'woocommerce'),
'required' => true,
'class' => array('form-row-last'),
'clear' => false
);*/

// Remove Address_2 Fields

unset($fields['billing']['billing_address_2']);
//unset($fields['shipping']['shipping_address_2']);

// Make Address_1 Fields Half Width

//$fields['billing']['billing_address_1']['class'] = array('form-row-first');
//$fields['shipping']['shipping_address_1']['class'] = array('form-row-first');

$fields['billing']['billing_country_field']['class'] = array('form-row-first');

// Billing: Sort Fields

$newfields['billing']['billing_first_name'] = $fields['billing']['billing_first_name'];
$newfields['billing']['billing_last_name'] = $fields['billing']['billing_last_name'];
$newfields['billing']['billing_company'] = $fields['billing']['billing_company'];
$newfields['billing']['billing_email'] = $fields['billing']['billing_email'];
$newfields['billing']['billing_phone'] = $fields['billing']['billing_phone'];
$newfields['billing']['billing_phone_confirm'] = $fields['billing']['billing_phone_confirm'];
$newfields['billing']['billing_country'] = $fields['billing']['billing_country'];
$newfields['billing']['billing_address_1'] = $fields['billing']['billing_address_1'];
//$newfields['billing']['billing_address_2'] = $fields['billing']['billing_address_2'];
$newfields['billing']['billing_city'] = $fields['billing']['billing_city'];
$newfields['billing']['billing_postcode'] = $fields['billing']['billing_postcode'];
$newfields['billing']['billing_state'] = $fields['billing']['billing_state'];

// Shipping: Sort Fields

$newfields['shipping']['shipping_first_name'] = $fields['shipping']['shipping_first_name'];
$newfields['shipping']['shipping_last_name'] = $fields['shipping']['shipping_last_name'];
$newfields['shipping']['shipping_company'] = $fields['shipping']['shipping_company'];
$newfields['shipping']['shipping_country'] = $fields['shipping']['shipping_country'];
$newfields['shipping']['shipping_address_1'] = $fields['shipping']['shipping_address_1'];
$newfields['shipping']['shipping_houseno'] = $fields['shipping']['shipping_houseno'];
$newfields['shipping']['shipping_city'] = $fields['shipping']['shipping_city'];
$newfields['shipping']['shipping_state'] = $fields['shipping']['shipping_state'];
$newfields['shipping']['shipping_postcode'] = $fields['shipping']['shipping_postcode'];

$checkout_fields = array_merge( $fields, $newfields);
return $checkout_fields;
}

现在的问题是确认,如果不匹配就不应该验证

这是我现在使用的

add_action( 'woocommerce_after_checkout_validation', 'wc_check_confirm_phone_matches_checkout', 10, 2 );

function wc_check_confirm_phone_matches_checkout( $posted ) {
$checkout = WC()->checkout;

if ( strcmp( $posted['billing_phone'], $posted['billing_phone_confirm_field'] ) !== 0 ) {
wc_add_notice( __( 'Phone number do not match.', 'woocommerce' ), 'error' );
}

}

这里的问题是总是显示“电话号码不匹配”。即使匹配,也需要帮助

关于javascript - 如何在 woocommerce 结账页面添加另一个电话字段进行确认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41758416/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com