Skip to content

Instantly share code, notes, and snippets.

@mahbubme
Created March 1, 2016 11:15
Show Gist options
  • Save mahbubme/10b50a7e8a1b19a59e86 to your computer and use it in GitHub Desktop.
Save mahbubme/10b50a7e8a1b19a59e86 to your computer and use it in GitHub Desktop.
Remove Dokan seller registration form default validation and add new validation.
// remove the filter
remove_filter( 'woocommerce_process_registration_errors', 'dokan_seller_registration_errors' );
remove_filter( 'registration_errors', 'dokan_seller_registration_errors' );
// New registration form erros handling
function dokan_update_seller_registration_errors( $error ) {
$allowed_roles = apply_filters( 'dokan_register_user_role', array( 'customer', 'seller' ) );
// is the role name allowed or user is trying to manipulate?
if ( isset( $_POST['role'] ) && !in_array( $_POST['role'], $allowed_roles ) ) {
return new WP_Error( 'role-error', __( 'Cheating, eh?', 'dokan' ) );
}
$role = $_POST['role'];
if ( $role == 'seller' ) {
$phone = trim( $_POST['phone'] );
if ( empty( $phone ) ) {
return new WP_Error( 'phone-error', __( 'Please enter your phone number.', 'dokan' ) );
}
}
return $error;
}
add_filter( 'woocommerce_process_registration_errors', 'dokan_update_seller_registration_errors' );
add_filter( 'registration_errors', 'dokan_update_seller_registration_errors' );
@devblissit
Copy link

'remove_filter' not working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment