Last active
November 17, 2021 14:53
-
-
Save hiendnguyen/51f3d3f841088488b6b5e8250f29c2eb to your computer and use it in GitHub Desktop.
WooCommerce Registration Custom Fields Validation
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. */ | |
function wooc_validate_extra_register_fields( $username, $email, $validation_errors ) { | |
if ( isset( $_POST['billing_first_name'] ) && empty( $_POST['billing_first_name'] ) ) { | |
$validation_errors->add( 'billing_first_name_error', __( 'What\'s your first name?', 'woocommerce' ) ); | |
} | |
if ( isset( $_POST['billing_last_name'] ) && empty( $_POST['billing_last_name'] ) ) { | |
$validation_errors->add( 'billing_last_name_error', __( 'What\'s your last name?', 'woocommerce' ) ); | |
} | |
} | |
add_action( 'woocommerce_register_post', '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