Skip to content

Instantly share code, notes, and snippets.

@mahbubme
Created March 1, 2016 11:15

Revisions

  1. mahbubme created this gist Mar 1, 2016.
    28 changes: 28 additions & 0 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    // 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' );