Skip to content

Instantly share code, notes, and snippets.

@hiendnguyen
Last active November 17, 2021 14:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiendnguyen/51f3d3f841088488b6b5e8250f29c2eb to your computer and use it in GitHub Desktop.
Save hiendnguyen/51f3d3f841088488b6b5e8250f29c2eb to your computer and use it in GitHub Desktop.
WooCommerce Registration Custom Fields Validation
<?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