Want to customize the “My Account” page? This PHP code adds ACF fields, allowing users to input and save additional information. Enhance user experience effortlessly!
add_action('woocommerce_edit_account_form', 'codebykp_add_acf_fields_to_account');
function codebykp_add_acf_fields_to_account() {
$field_value = get_field('custom_field_name', 'user_' . get_current_user_id());
echo '<p class="form-row form-row-wide">
<label for="custom_field_name">Custom Field</label>
<input type="text" class="input-text" name="custom_field_name" id="custom_field_name" value="' . esc_attr($field_value) . '" />
</p>';
}
add_action('woocommerce_save_account_details', 'codebykp_save_acf_fields_to_account');
function codebykp_save_acf_fields_to_account($user_id) {
update_field('custom_field_name', $_POST['custom_field_name'], 'user_' . $user_id);
}