Adding a custom field to registration form on checkout
-
Hello guys,
I ran into a problem with adding a custom field to the registration form on the woocommerce checkout form. On the registration form on my-account page I have everything in place and working, but I don’t get it to work on the checkout page. I succeeded with getting a custom field showing up by overriding the woocommerce tamplate (I know, bad practice), but I didn’t succeed with saving the value in the database. Again, on my-account page evrything is working with simillar code.
What I tried is the following code:
add_action(‘woocommerce_checkout_update_user_meta’, my_custom_checkout_field_update_user_meta’);
function my_custom_checkout_field_update_user_meta( $user_id ) {
if ($user_id && $_POST[‘group_id’]) {
$wpdb->insert(
‘wp_groups_user_group’,
array( ‘user_id’ => $user_id, ‘group_id’ => $_POST[‘group_id’] ),
array( ‘%s’, ‘%s’ )
);
}
}As you can see, it supposed to add the user to a group. However, the code is not working… It gives an internal error(from woocommerce) and the user gets registered assigned to the wrong group.
- The topic ‘Adding a custom field to registration form on checkout’ is closed to new replies.