0
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;
}
By adding this documentation, you enhance the maintainability of the code and make it easier for others to understand its functionality, improving collaboration and future updates.
