1. Home
  2. WooCommerce Wholesale Pro
  3. Advanced Usage

How to save wholesale registration fields to the user profile page

WooCommerce Wholesale Pro lets you create a wholesale user registration form with up to 10 fields. This article is aimed at developers and explains how to store the data from these fields as custom fields on the user profile page.

If you don't know how to follow these instructions then we recommend posting a job on Codeable, where one of their WordPress experts will send you a quote.

We've partnered with Codeable to provide our customers with expert help if required.

Code snippet

The following code snippet will add an extra tab to the WooCommerce user account page containing the extra fields from the wholesale registration form. Add it to the functions file in your theme or child theme, or by using a code snippets plugin:

function wholesale_pro_query_vars( $vars ) {
    $vars['more-info'] = 'more-info';
    return $vars;
}
add_filter( 'woocommerce_get_query_vars', 'wholesale_pro_query_vars', 0 );

function wholesale_pro_link_my_account( $items ) {
$logout = $items['customer-logout'];
unset( $items['customer-logout'] );
    $items['more-info'] = __( 'More info' );
$items['customer-logout'] = $logout;
 
    return $items;
}
add_filter( 'woocommerce_account_menu_items', 'wholesale_pro_link_my_account' );

function wholesale_pro_endpoint_more_info_title( $title ) {
return __( 'More info' );
}
add_filter( 'woocommerce_endpoint_more-info_title', 'wholesale_pro_endpoint_more_info_title' );

function wholesale_pro_new_tab_content() {
$fields = get_option( 'wcwp_registration_fields', [] );

$user_id = get_current_user_id();
 
if ( empty( $fields ) ) {
echo __( 'No information available at this time' );
return;
}

foreach ( $fields as $field ) {
$label = $field['label'];
$id = $field['id'];

$value = get_user_meta( $user_id, $id, true );

echo $label . ': ' . $value . '<br>';
}
} 
add_action( 'woocommerce_account_more-info_endpoint', 'wholesale_pro_new_tab_content' );

Once you have done this, the field name will appear first, followed by a colon and then the data entered by the user:

Save wholesale registration form fields user profile

Refresh your permalinks by visiting Settings → Permalinks if you see any 404/not found errors.

Can I map the address fields from my registration form to the WooCommerce address fields?

Unfortunately this is not currently possible and we are tracking the amount of demand for a way to do this. If you would like this, please send us a feature request and we will add you as another 'vote' for it.

Related Articles

If searching the knowledge base hasn't answered your question, please contact support.