1. Home
  2. WC Vendors Pro
  3. How To
  4. Custom Fields to Vendor Settings Page (Pro)

Custom Fields to Vendor Settings Page (Pro)

This code adds a custom field to the Dashboard > Settings page for your vendors to provide you extra bits of info you may need from them. Duplicate for each custom field you need, renaming the meta keys and functions each time so they are not duplicated.  For WC Vendors Pro, the updates you need to make are in three parts as described below.

Part 1:  Add this code to your theme’s functions.php file:

/* WC Vendors Pro - My Custom Field */
function store_bank_details( ){ 
	if ( class_exists( 'WCVendors_Pro' ) ){ 
		$key = '_wcv_custom_settings_bankname'; 
		$value = get_user_meta( get_current_user_id(), $key, true ); 
		// Bank Name
		WCVendors_Pro_Form_Helper::input( array(  
			'id' 				=> $key, 
			'label' 			=> __( 'Bank Name', 'wcvendors-pro' ), 
			'placeholder' 			=> __( 'First Bank', 'wcvendors-pro' ), 
			'desc_tip' 			=> 'true', 
			'description' 			=> __( 'Your local bank name', 'wcvendors-pro' ), 
			'type' 				=> 'text', 
			'value'				=> $value, 
			)
		);
	} 
}

Part 2: This adds the custom field to the wp-admin > Users > Edit User screen, if you need it to, and also goes in your theme’s functions.php file:

//Add the field 
add_action( 'wcvendors_admin_after_commission_due', 'wcv_store_bank_details_admin' );
function wcv_store_bank_details_admin( $user ) {
?>
  <tr>
    <th><label for="_wcv_custom_settings_bankname"><?php _e( 'Bank Name', 'wcvendors-pro' ); ?></label></th>
    <td><input type="text" name="_wcv_custom_settings_bankname" id="_wcv_custom_settings_bankname" value="<?php echo get_user_meta( $user->ID, '_wcv_custom_settings_bankname', true ); ?>" class="regular-text"></td>
  </tr>
<?php
}

// Save the details on the back end when updating the user
add_action( 'wcvendors_update_admin_user', 'pv_save_merchant_id' );
function save_bank_details( $user_id ){
 if ( isset( $_POST['_wcv_custom_settings_bankname'] ) ) {
 update_user_meta( $user_id, '_wcv_custom_settings_bankname', $_POST['_wcv_custom_settings_bankname'] );
 }
}
?>

Part 3: In order to show the custom field on your Pro Settings page, you need to add the function you just created above to the template. Copy /plugins/wc-vendors-pro/templates/dashboard/store-settings.php to /themes/yourtheme-child/wc-vendors/dashboard/store-settings.php and add this wherever you want the field to show up.

<?php store_bank_details(  ); ?>

 

actions

Updated on February 3, 2019

Was this article helpful?