Theme and Plugin Support
-
AuthorPosts
-
-
March 19, 2021 at 6:16 PM #117857xyzzyestudioweb.comParticipant
Hi, I’ve just create some functions to add custom fields on vendor registration form. The metadata generated is stored on vendor profile user on the database, but it’s not showing on the vendor approval page.
Here’s my code
// Campos personalizados en registro de vendedor function wcmp_vendor_register_form_fields() { ?> <div class="wcmp-regi-form-row wcmp-regi-6"> <label for="user_name"><?php _e('Tu nombre','astra-child'); ?> *</label><br/> <small><?php _e('Dinos tu nombre', 'astra-child'); ?></small> <input required type="text" name="user_name" id="user_name" class="input" value="" tabindex="30" /> </div> <div class="wcmp-regi-form-row wcmp-regi-6"> <label for="user_surname"><?php _e('Tus apellidos','astra-child'); ?></label><br/> <small><?php _e('Dinos tus apellidos', 'astra-child'); ?></small> <input type="text" name="user_surname" id="user_surname" class="input" value="" tabindex="30" /> </div> <div class="wcmp-regi-form-row wcmp-regi-12"> <label for="author_description"><?php _e('Descripción','astra-child'); ?> *</label><br/> <small><?php _e('Tu biografía pública como autor... ¡cuéntale al mundo sobre ti!', 'astra-child'); ?></small> <textarea required type="textarea" name="author_description" id="author_description" value="" tabindex="30"></textarea> </div> <div class="wcmp-regi-form-row wcmp-regi-6"> <label for="user_web"><?php _e('Tu web','astra-child'); ?></label><br/> <small><?php _e('¿Tienes una web? ¡Muéstranosla!', 'astra-child'); ?></small> <input type="url" name="user_web" id="user_web" class="input" value="" tabindex="30" /> </div> <div class="wcmp-regi-form-row wcmp-regi-6"> <label for="user_image"><?php _e('Tu foto de perfil','astra-child'); ?></label><br/> <small><?php _e('Ponte guapo/a... ¡Tienes una cita en Comicflex!', 'astra-child'); ?></small> <input type="file" name="user_image" id="user_image" class="input" value="" tabindex="30" accept="image/x-png,image/jpeg"/> </div> <div class="wcmp-regi-form-row wcmp-regi-6"> <label for="iban_number"><?php _e('IBAN','astra-child'); ?> *</label><br/> <small><?php _e('El número de cuenta al que transferiremos tus comisiones', 'astra-child'); ?></small> <input required type="text" name="iban_number" id="iban_number" class="input" value="" tabindex="30" /> </div> <div class="wcmp-regi-form-row wcmp-regi-6"> <label for="youtube"><?php _e('Canal de YouTube','astra-child'); ?></label><br/> <small><?php _e('¿Eres YouTuber? ¡Déjanos la URL de tu canal!', 'astra-child'); ?></small> <input type="url" name="youtube" id="youtube" class="input" value="" tabindex="30" /> </div> <div class="wcmp-regi-form-row wcmp-regi-6"> <label for="facebook"><?php _e('URL de Facebook','astra-child'); ?></label><br/> <small><?php _e('Tu perfil en Facebook', 'astra-child'); ?></small> <input type="url" name="facebook" id="facebook" class="input" value="" tabindex="30" /> </div> <div class="wcmp-regi-form-row wcmp-regi-6"> <label for="instagram"><?php _e('URL de Instagram','astra-child'); ?></label><br/> <small><?php _e('Tu perfil en Instagram', 'astra-child'); ?></small> <input type="url" name="instagram" id="instagram" class="input" value="" tabindex="30" /> </div> <div class="wcmp-regi-form-row wcmp-regi-6"> <label for="twitter"><?php _e('URL de Twitter','astra-child'); ?></label><br/> <small><?php _e('Tu perfil en Twitter', 'astra-child'); ?></small> <input type="url" name="twitter" id="twitter" class="input" value="" tabindex="30" /> </div> <div class="wcmp-regi-form-row wcmp-regi-6"> <label for="linkedin"><?php _e('URL de Linkedin','astra-child'); ?></label><br/> <small><?php _e('Tu perfil en Linkedin', 'astra-child'); ?></small> <input type="url" name="linkedin" id="linkedin" class="input" value="" tabindex="30" /> </div> <?php } add_action('wcmp_vendor_register_form', 'wcmp_vendor_register_form_fields'); // Añadimos campos personalizados para vista en vendedor pendiente function save_dash($wcmp_vendor_fields, $customer_id) { $wcmp_vendor_fields = array( array('value' => $_POST['user_name'], 'label'=> 'Nombre','type' => 'text'), array('value' => $_POST['user_surname'], 'label'=> 'Apellidos','type' => 'text'), array('value' => $_POST['author_description'], 'label'=> 'Descripción','type' => 'text'), array('value' => $_POST['user_web'], 'label'=> 'Web','type' => 'url'), array('value' => $_POST['iban_number'], 'label'=> 'IBAN','type' => 'text'), array('value' => $_POST['youtube'], 'label'=> 'YouTube','type' => 'url'), array('value' => $_POST['facebook'], 'label'=> 'Facebook','type' => 'url'), array('value' => $_POST['instagram'], 'label'=> 'Instagram','type' => 'url'), array('value' => $_POST['linkedin'], 'label'=> 'Linkedin','type' => 'url') ); return $wcmp_vendor_fields; } add_filter('wcmp_save_registration_fields', 'save_dash', 10 , 2); apply_filters('wcmp_save_registration_fields', $wcmp_vendor_fields, $customer_id); // Seteamos campos personalizados a usuario vendedor final function vendor_registration_formdata_save($user_id) { $name = ''; $surname = ''; if ($_SERVER['REQUEST_METHOD'] == 'POST') { if(isset($_POST['user_name'])) { $name = sanitize_text_field($_POST['user_name']); $surname = sanitize_text_field($_POST['user_surname']); $shop = $name . ' ' . $surname; //$slug = sanitize_title($shop); update_user_meta($user_id,'first_name', $name); update_user_meta($user_id,'last_name', $surname); wp_update_user(array('ID' => $user_id, 'display_name' => $shop)); } if (isset($_POST['author_description'])) { update_user_meta($user_id, '_vendor_description', sanitize_text_field($_POST['author_description'])); } if (isset($_POST['user_web'])) { wp_update_user(array('ID' => $user_id, 'user_url' => sanitize_text_field($_POST['user_web']))); } if (isset($_POST['iban_number'])) { update_user_meta($user_id, '_vendor_iban', sanitize_text_field($_POST['iban_number'])); update_user_meta($user_id, '_vendor_payment_mode', 'direct_bank'); update_user_meta($user_id, '_vendor_bank_account_type', 'current'); } if (isset($_FILES['user_image'])) { $file = $_FILES['user_image']; $attachment_id = upload_user_file($file); if($attachment_id) { update_user_meta($user_id,'_vendor_image',$attachment_id); update_user_meta($user_id, 'user_avatar', $attachment_id); } } if (isset($_POST['youtube'])) { update_user_meta($user_id, '_vendor_youtube', sanitize_text_field($_POST['youtube'])); } if (isset($_POST['facebook'])) { update_user_meta($user_id, '_vendor_fb_profile', sanitize_text_field($_POST['facebook'])); } if (isset($_POST['instagram'])) { update_user_meta($user_id, '_vendor_instagram', sanitize_text_field($_POST['instagram'])); } if (isset($_POST['twitter'])) { update_user_meta($user_id, '_vendor_twitter_profile', sanitize_text_field($_POST['twitter'])); } if (isset($_POST['linkedin'])) { update_user_meta($user_id, '_vendor_linkdin_profile', sanitize_text_field($_POST['linkedin'])); } update_user_meta($user_id, '_vendor_country', 'España'); update_user_meta($user_id, '_vendor_country_code', 'ES'); } } add_action('after_register_wcmp_vendor', 'vendor_registration_formdata_save'); // Función para poder enviar ficheros desde el front function upload_user_file( $file = array() ) { require_once( ABSPATH . 'wp-admin/includes/admin.php' ); $file_return = wp_handle_upload( $file, array('test_form' => false ) ); if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) { return false; } else { $filename = $file_return['file']; $attachment = array( 'post_mime_type' => $file_return['type'], 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), 'post_content' => '', 'post_status' => 'inherit', 'guid' => $file_return['url'] ); $attachment_id = wp_insert_attachment( $attachment, $file_return['url'] ); require_once(ABSPATH . 'wp-admin/includes/image.php'); $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); wp_update_attachment_metadata( $attachment_id, $attachment_data ); if( 0 < intval( $attachment_id ) ) { return $attachment_id; } } return false; }
CopyI think the code is fine but I attach a screenshot of the result.
Thank you.
-
March 19, 2021 at 7:56 PM #117879Raju The Cool GuyKeymaster
Hi,
These are vendors’ application data. Which is saved in wcmp_vendor_fields this user meta. And datas are displayed by wcmp_vendor_preview_template this function ( line no 1026 ). -
March 19, 2021 at 7:58 PM #117880xyzzyestudioweb.comParticipant
Okay, i checked the database and that meta doesn’t exists.
How i can store this data o that meta?
Thank you so much!
-
March 19, 2021 at 8:00 PM #117881xyzzyestudioweb.comParticipant
I think the problem is on this function… it’s possible?
// Añadimos campos personalizados para vista en vendedor pendiente function save_dash($wcmp_vendor_fields, $customer_id) { $wcmp_vendor_fields = array( array('value' => $_POST['user_name'], 'label'=> 'Nombre','type' => 'text'), array('value' => $_POST['user_surname'], 'label'=> 'Apellidos','type' => 'text'), array('value' => $_POST['author_description'], 'label'=> 'Descripción','type' => 'text'), array('value' => $_POST['user_web'], 'label'=> 'Web','type' => 'url'), array('value' => $_POST['iban_number'], 'label'=> 'IBAN','type' => 'text'), array('value' => $_POST['youtube'], 'label'=> 'YouTube','type' => 'url'), array('value' => $_POST['facebook'], 'label'=> 'Facebook','type' => 'url'), array('value' => $_POST['instagram'], 'label'=> 'Instagram','type' => 'url'), array('value' => $_POST['linkedin'], 'label'=> 'Linkedin','type' => 'url') ); return $wcmp_vendor_fields; } add_filter('wcmp_save_registration_fields', 'save_dash', 10 , 2); apply_filters('wcmp_save_registration_fields', $wcmp_vendor_fields, $customer_id);
Copy -
March 19, 2021 at 11:04 PM #117890xyzzyestudioweb.comParticipant
Okay, finally i found the solution. Simply with this code at the end of my vendor_registration_formdata_save function:
$wcmp_vendor_fields = array(); $wcmp_vendor_fields = apply_filters('wcmp_save_registration_fields', $wcmp_vendor_fields, $user_id); update_user_meta($user_id, 'wcmp_vendor_fields', $wcmp_vendor_fields);
CopyThanks and mark it as resolved!
-
-
AuthorPosts
The topic ‘Custom fields on vendor registration doesn’t show on vendor approval page’ is closed to new replies.