[resolved] Auto populate value fields in checkout billing/shipping area (8 posts)

  1. nutt318
    Posted 3 years ago #

    I was able to figure out how to auto populate the users first name and last name within the my-account page on woocommerce by editing form-edit-address.php and adding the following code to line 35 and it works great.

    if (!$value && ($key=='billing_first_name' || $key =='shipping_first_name')) $value = $current_user->user_firstname;
    if (!$value && ($key=='billing_last_name' || $key =='shipping_last_name')) $value = $current_user->user_lastname;

    Now when going through the check out process I want it to be able to auto populate those same default value fields for firstname and lastname if they didnt update them on the my account page. I thought it would carry over but there must be something im not seeing.



  2. Scott Basgaard
    Posted 3 years ago #

    Take a look at:


    You can filter these fields.

    For example:

    // Hook in
    add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
    // Our hooked in function - $fields is passed via the filter!
    function custom_override_checkout_fields( $fields ) {
         $fields['billing']['billing_first_name']['default'] = 'test';
         return $fields;

    That should help point you in the right direction.

    Hope this helps, cheers!

  3. nutt318
    Posted 3 years ago #

    Thanks Scott!

    That worked perfect

  4. justradar
    Posted 3 years ago #

    i'm using this:

    $fields['billing']['billing_first_name']['default'] = $current_user->user_firstname;

    but it's not working ... what am i doing wrong?

  5. Amsterdammer
    Posted 3 years ago #

    you forgot to add this:
    $current_user = wp_get_current_user();

  6. justradar
    Posted 3 years ago #

    ah! thanks!

  7. visualxl
    Posted 2 years ago #

    Scott!! You are good! I have been spending the whole day trying to set the value. I never knew there is this thing called 'default'!

  8. visualxl
    Posted 2 years ago #

    After the recent woo commerce updates, I am no longer able to fill the default zip code automatically. I did opened another thread for this. Anyone know how to solve this?

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic