-
-
Save brunoalvarenga/e255f07a1392d222d6aeb7d877ce4797 to your computer and use it in GitHub Desktop.
Remove Dokan seller registration form default validation and add new validation.
This file contains hidden or 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
// 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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment