I’m using Dokan on a WooCommerce marketplace. I’ve already made the Shop URL field optional for vendor registration using filters, and vendors can now successfully register without filling that field. However, the Shop URL field still shows a red as

WPTurbo » Snippets » I’m using Dokan on a WooCommerce marketplace. I’ve already made the Shop URL field optional for vendor registration using filters, and vendors can now successfully register without filling that field. However, the Shop URL field still shows a red as
0

Created with:

Visibility: 

public

Creator: TO

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project
					<?php

// Add a filter to modify the seller registration form fields in Dokan
add_filter( 'dokan_seller_reg_form_fields', 'furnimax_override_shop_url_completely' );

/**
 * Modify the Shop URL field in the seller registration form.
 *
 * This function updates the Shop URL field to make it optional, remove the required asterisk,
 * and add helper text for clarity.
 *
 * @param array $fields The existing form fields from the Dokan registration form.
 * 
 * @return array Updated form fields with the Shop URL field modified to be optional.
 */
function furnimax_override_shop_url_completely( array $fields ): array {
    // Check if the Shop URL field exists in the form fields
    if ( isset( $fields['shop_url'] ) ) {
        // Set the Shop URL field as not required
        $fields['shop_url']['required'] = false;

        // Update the label for the Shop URL field to exclude the asterisk
        $fields['shop_url']['label'] = '<span>' . esc_html( 'Shop URL' ) . '</span>'; // Label without asterisk
        
        // Set a description for the Shop URL field to provide helper text
        $fields['shop_url']['desc'] = esc_html( '(Furniture Store sellers only)' ); // Escape helper text
        
        // Remove the 'required' class from the Shop URL field
        $fields['shop_url']['class'] = array(); // Remove 'required' class
    }

    // Return the modified fields
    return $fields;
}

// Add a filter to modify validation for the seller registration form
add_filter( 'dokan_reg_form_field_validation', 'furnimax_disable_shop_url_validation_backend', 10, 2 );

/**
 * Disable validation for the Shop URL field in the registration form.
 *
 * This function removes the Shop URL field from the list of required fields,
 * ensuring no validation error occurs if it is left empty.
 *
 * @param array $required_fields The fields that are required during registration.
 * @param string $role The user role being registered (e.g., vendor, customer).
 * 
 * @return array Updated required fields with the Shop URL field removed.
 */
function furnimax_disable_shop_url_validation_backend( array $required_fields, string $role ): array {
    // Check if the Shop URL field is in the required fields
    if ( isset( $required_fields['shop_url'] ) ) {
        // Remove the Shop URL field from the required fields
        unset( $required_fields['shop_url'] );
    }

    // Return the modified required fields
    return $required_fields;
}
				

Add the following CSS to your theme or plugin to ensure the Shop URL field does not visually indicate it is required:

If you have any custom JavaScript that manipulates the DOM or adds behavior based on the required status of the Shop URL field, make sure to remove or modify those behaviors accordingly.

By ensuring the field is set as optional in the PHP code, removing any required classes, and adding custom CSS, you can completely remove the visual indicators that suggest the Shop URL field is required. If any JS behavior is still affecting it, you may need to debug that separately.

Make sure to test these changes thoroughly to confirm that the field functions and appears as intended in the registration form.

Register an account to save your snippets or go Pro to get more features.