Skip to content

Instantly share code, notes, and snippets.

@NorthTexasCreative
Created October 13, 2022 20:04
Show Gist options
  • Save NorthTexasCreative/3720118561ab18257030923eede9e122 to your computer and use it in GitHub Desktop.
Save NorthTexasCreative/3720118561ab18257030923eede9e122 to your computer and use it in GitHub Desktop.
Fill in WooCommerce Order fields from user profile
add_filter( 'woocommerce_checkout_fields' , 'ahmadyani_checkout_field_defaults', 20 );
function ahmadyani_checkout_field_defaults( $fields ) {
$user = get_user_meta(get_current_user_id());
$first_name = $user ? $user['shipping_first_name'][0] : '';
$last_name = $user ? $user['shipping_last_name'][0] : '';
$company = $user ? $user['shipping_company'][0] : '';
$shipping_address_1 = $user ? $user['shipping_address_1'][0] : '';
$shipping_address_2 = $user ? $user['shipping_address_2'][0] : '';
$shipping_city = $user ? $user['shipping_city'][0] : '';
$shipping_state = $user ? $user['shipping_state'][0] : '';
$shipping_postcode = $user ? $user['shipping_postcode'][0] : '';
$fields['billing']['billing_first_name']['default'] = $first_name;
$fields['billing']['billing_last_name']['default'] = $last_name;
$fields['billing']['billing_company']['default'] = $company;
$fields['billing']['billing_address_1']['default'] = $shipping_address_1;
$fields['billing']['billing_address_2']['default'] = $shipping_address_2;
$fields['billing']['billing_city']['default'] = $shipping_city;
$fields['billing']['billing_state']['default'] = $shipping_state;
$fields['billing']['billing_postcode']['default'] = $shipping_postcode;
return $fields;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment