WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. nutt318
    Member
    Posted 1 year 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.

    Thanks!

    http://wordpress.org/extend/plugins/woocommerce/

  2. Scott Basgaard
    Member
    Posted 1 year ago #

    Take a look at:

    http://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/

    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!
    Scott

  3. nutt318
    Member
    Posted 1 year ago #

    Thanks Scott!

    That worked perfect

  4. justradar
    Member
    Posted 1 year 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
    Member
    Posted 1 year ago #

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

  6. justradar
    Member
    Posted 1 year ago #

    ah! thanks!

  7. visualxl
    Member
    Posted 7 months 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
    Member
    Posted 7 months 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

About this Topic