• In my functions.php I have a piece of code which uses the info from the current user as default to fill the billing fields.

    This works perfect (well not completely, otherwise I wouldn’t ask my question), only the postcode is not being filled, the rest of the fields are filled as they should.

    This is the code I have:

    /* Filling billing fields with current user info */
    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 ) {
    	$current_user = wp_get_current_user();
    	//echo $current_user;
        $fields['billing']['billing_first_name']['default'] = $current_user->user_firstname;
    	$fields['billing']['billing_last_name']['default'] = $current_user->user_lastname;
    	$fields['billing']['billing_company']['default'] = $current_user->company_name;
    	$fields['billing']['billing_address_1']['default'] = $current_user->user_address;
    	$fields['billing']['billing_address_2']['default'] = "";
    	$fields['billing']['billing_postcode']['default'] = $current_user->zip_code;
    	$fields['billing']['billing_city']['default'] = $current_user->user_city;
    	$fields['billing']['billing_email']['default'] = $current_user->user_email;
    	$fields['billing']['billing_phone']['default'] = $current_user->phone_number;
    	unset($fields['order']['order_comments']);
    
         	return $fields;
    }

    I have made small test (on the checkout page) to see if the postcode is actually past through and it is.

    Is there something changed since the last update from woocommerce, so the postcode is not added?
    This is kinda frustrating.

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘woocommerce override_checkout_fields postcode not taken from current_user’ is closed to new replies.