Shipping address validation
-
I have a shipping phone field in my shipping address section, and below is the code I validate the phone numbers customers fill in.
add_action( 'woocommerce_checkout_process', 'custom_shipping_phone_validation' ); add_action( 'woocommerce_after_save_address_validation', 'custom_shipping_phone_validation' ); function custom_shipping_phone_validation() { $is_correct = preg_match('/^1[0-9]{10}$/', $_POST['shipping_phone']); if ( $_POST['shipping_phone'] && !$is_correct) { wc_add_notice( __( 'The phone number should be 11 digits and start with 1.' ), 'error' ); } }It works fine. But when adding a new shipping address on the my account page, the validation above doesn’t work properly, because the name of shipping phone field changes to ‘shipping2_phone’, and there will be ‘shipping3_phone’, ‘shipping4_phone’, ‘shipping5_phone’, etc. if more shipping addresses are added into the section, so how to modify the code above to validate the phone numbers? I’m not very familiar with php language, any help would be greatly appreciated.
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
The topic ‘Shipping address validation’ is closed to new replies.