Vendor (custom code) registration fields. How to make not required en reorder?

We're shifting our Forum based support to a more dedicated support system!

We'll be closing our Forum support from 10th June, 2020 and move to Email Support assistance.

  • If you are a WCFM premium add-ons user, contact us- here
  • Want to know more before buying our add-ons? Send Pre sale queries- here
  • If you are a WCFM free user, please open a support ticket at WordPress.org
  • For WCFM App related queries, reach us- here
From now the forum will be read-only!

Multi Vendor Marketplace Plugin | WCFM Marketplace Forums WCFM – Ultimate Vendor (custom code) registration fields. How to make not required en reorder?

Viewing 1 reply thread
  • Author
    Posts
    • #119028
      Henriette
      Participant

      Hi,

      I found on one of this forums this functions.php code for letting vendor choose a suitable category at registration.

      add_action( 'end_wcfm_membership_registration_form', function() {
      	$selected_categories = array();
      	
      	$product_categories   = get_terms( 'product_cat', 'orderby=name&hide_empty=0&parent=0' );
      	$p_category_options   = array();
      	foreach ( $product_categories as $cat ) {
      		$p_category_options[$cat->term_id] = array( 'name' => $cat->name, 'parent' => 0 );
      	}
      	
      	if( !empty( $p_category_options ) ) showRegistrationCategoryHierarchySelector( $p_category_options, $selected_categories );
      	?>
      	<script>
      	jQuery(document).ready(function($) {
      		$('.wcfm_category_hierarchy').each(function() {
      			$(this).change(function() {
      				$level = parseInt($(this).data('level'));
      				$value = $(this).val();
      				if( $('.p_category_'+($level+1)).length > 0 ) {
      					$('.p_category_'+($level+1)).addClass('wcfm_custom_hide');
      					$('.p_category_label_'+($level+1)).addClass('wcfm_custom_hide');
      					if( $value ) {
      						$.each($value, function( $i, $svalue ) {
      							if( $('.p_category_'+($level+1)).find('.cat_parent_'+$svalue).length > 0 ) {
      								$('.p_category_'+($level+1)).removeClass('wcfm_custom_hide');
      								$('.p_category_label_'+($level+1)).removeClass('wcfm_custom_hide');
      							}
      						});
      					}
      					$level_1 = $('.p_category_'+($level+1)).val();
      					$('.p_category_'+($level+1)).val('');
      					$('.p_category_'+($level+1)).find('option').addClass('wcfm_custom_hide');
      					if( $value ) {
      						$.each($value, function( $i, $svalue ) {
      							$('.p_category_'+($level+1)).find('.cat_parent_'+$svalue).removeClass('wcfm_custom_hide');
      						});
      					}
      					if( $level_1 ) {
      						if( !$('.p_category_'+($level+1)).find('option[value="'+$level_1+'"]').hasClass('wcfm_custom_hide') ) {
      							$('.p_category_'+($level+1)).val($level_1);
      						}
      					}
      					$('.p_category_'+($level+1)).change();
      				}
      			}).change();
      			
      		});
      	});
      	</script>
      	<?php
      });
      
      function showRegistrationCategoryHierarchySelector( $p_category_options, $selected_categories, $level = 0 ) {
      	global $WCFM, $WCFMch;
      	
      	$p_category_child_options = array();
      	$ptax_custom_arrtibutes = apply_filters( 'wcfm_taxonomy_custom_attributes', array(), 'product_cat' );
      	?>
      	<p class="wcfm_title p_category_label_<?php echo $level; ?>">
      		<strong>
      			<?php 
      			echo apply_filters( 'wcfm_taxonomy_custom_label', '', 'product_cat' );
      			if( $level ) _e( 'Sub-', 'wcfm-category-hierarchy' ); 
      			_e( 'Categories', 'wc-frontend-manager' ); 
      			?>
      		</strong>
      	</p>
      	<label class="screen-reader-text" for="product_cats">
      		<?php 
      		if( $level ) echo __( 'Sub-', 'wcfm-category-hierarchy' );
      		echo apply_filters( 'wcfm_taxonomy_custom_label', __( 'Categories', 'wc-frontend-manager' ), 'product_cat' ); 
      		?>
      	</label>
      	<select id="p_category_<?php echo $level; ?>" style="height: auto;" multiple name="reg_category[<?php echo $level; ?>][]" class="wcfm-select wcfm_category_hierarchy p_category_<?php echo $level; ?>" data-level="<?php echo $level; ?>" data-catlimit="1" <?php echo implode( ' ', $ptax_custom_arrtibutes ); ?>>
      		<option value=""><?php _e( '-- Selecteer Categorie --', 'wcfm-category-hierarchy' ); ?></option>
      		<?php
      		foreach( $p_category_options as $term_id => $term_details ) {
      			$cat_group_class = 'cat_parent_' . $term_details['parent'];
      			echo '<option class="' . $cat_group_class . '" value="' . esc_attr( $term_id ) . '"' . selected( in_array( $term_id, $selected_categories ), true, false ) . '>' . __( esc_html( $term_details['name'] ), 'wcfm-category-hierarchy' ) . '</option>';
      			
      			$product_child_taxonomies   = get_terms( 'product_cat', 'orderby=name&hide_empty=0&parent=' . absint( $term_id ) );
      			if ( $product_child_taxonomies ) {
      				foreach ( $product_child_taxonomies as $cat ) {
      					$p_category_child_options[$cat->term_id] = array( 'name' => $cat->name, 'parent' => $term_id );
      				}
      			}
      		}
      		?>
      	</select>
      	<?php
      	$level++;
      	if( !empty( $p_category_child_options ) ) showRegistrationCategoryHierarchySelector( $p_category_child_options, $selected_categories, $level );
      }
      
      add_action( 'wcfm_membership_registration', function( $member_id, $wcfm_membership_registration_form_data ) {
      	if( isset( $wcfm_membership_registration_form_data['reg_category'] ) ) {
      		update_user_meta( $member_id, 'wcfm_vendor_reg_category', $wcfm_membership_registration_form_data['reg_category'] );
      	}
      }, 50, 2 );

      This works like a charm but the only problem is that this is required. I do not want that because if there is no category for vendor to suit his store I have a custom field where vendor can add a category suggestion so I can make that category for him in WC admin.
      I can not find in the code how to make it not required. Can you please point me in the right direction?

      Also I wish to re-order the custom fields. Like “K.v.K. Nummer” is part of the shopinfo.
      And custom field for Suggested Categorie (“Categorie Suggestie”) needs to be beneath the categories so if there is no category to choose from than vendor can fill in his own.Please see attachment.
      Can you help me to achieve this please?

      And one more question.
      Is it possible to hide the custom fields from vendor profile page?
      I only need this information like K.v.K. Nummer to approve vendor and category suggestion to make the right category for vendor store.

      Thank you.

      Attachments:
      You must be logged in to view attached files.
    • #119422
      Auhouse.ru
      Participant

      +

Viewing 1 reply thread
  • You must be logged in to reply to this topic.