Created
November 8, 2016 14:13
-
-
Save claudiosanches/2c3f72a66089df5deac92e2c46f43af6 to your computer and use it in GitHub Desktop.
WooCommerce - Validating new "My account" registration fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Validate the extra register fields. | |
* | |
* @param WP_Error $validation_errors Errors. | |
* @param string $username Current username. | |
* @param string $email Current email. | |
* | |
* @return WP_Error | |
*/ | |
function wooc_validate_extra_register_fields( $errors, $username, $email ) { | |
if ( isset( $_POST['billing_first_name'] ) && empty( $_POST['billing_first_name'] ) ) { | |
$errors->add( 'billing_first_name_error', __( '<strong>Error</strong>: First name is required!', 'woocommerce' ) ); | |
} | |
if ( isset( $_POST['billing_last_name'] ) && empty( $_POST['billing_last_name'] ) ) { | |
$errors->add( 'billing_last_name_error', __( '<strong>Error</strong>: Last name is required!.', 'woocommerce' ) ); | |
} | |
if ( isset( $_POST['billing_phone'] ) && empty( $_POST['billing_phone'] ) ) { | |
$errors->add( 'billing_phone_error', __( '<strong>Error</strong>: Phone is required!.', 'woocommerce' ) ); | |
} | |
return $errors; | |
} | |
add_filter( 'woocommerce_registration_errors', 'wooc_validate_extra_register_fields', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment