Registration Form Doesn’t Work With Buddypress
-
I am trying to add extra fields into my registration form using the following code into the functions.php file in my child theme (One Social). The code should capture the data for woo commerce to use at the checkout.
//Adding Registration fields to the form
add_action( ‘register_form’, ‘adding_custom_registration_fields’ );
function adding_custom_registration_fields( ) {//lets make the field required so that i can show you how to validate it later;
$firstname = empty( $_POST[‘firstname’] ) ? ” : $_POST[‘firstname’];
$lastname = empty( $_POST[‘lastname’] ) ? ” : $_POST[‘lastname’];
?>
<div class=”form-row form-row-wide”>
<label for=”reg_firstname”><?php _e( ‘First Name’, ‘woocommerce’ ) ?><span class=”required”>*</span></label>
<input type=”text” class=”input-text” name=”firstname” id=”reg_firstname” size=”30″ value=”<?php echo esc_attr( $firstname ) ?>” />
</div>
<div class=”form-row form-row-wide”>
<label for=”reg_lastname”><?php _e( ‘Last Name’, ‘woocommerce’ ) ?><span class=”required”>*</span></label>
<input type=”text” class=”input-text” name=”lastname” id=”reg_lastname” size=”30″ value=”<?php echo esc_attr( $lastname ) ?>” />
</div><?php
}//Validation registration form after submission using the filter registration_errors
add_filter( ‘woocommerce_registration_errors’, ‘registration_errors_validation’ );/**
* @param WP_Error $reg_errors
*
* @return WP_Error
*/
function registration_errors_validation( $reg_errors ) {if ( empty( $_POST[‘firstname’] ) || empty( $_POST[‘lastname’] ) ) {
$reg_errors->add( ’empty required fields’, __( ‘Please fill in the required fields.’, ‘woocommerce’ ) );
}return $reg_errors;
}//Updating use meta after registration successful registration
add_action(‘woocommerce_created_customer’,’adding_extra_reg_fields’);function adding_extra_reg_fields($user_id) {
extract($_POST);
update_user_meta($user_id, ‘first_name’, $firstname);
update_user_meta($user_id, ‘last_name’, $lastname);
update_user_meta($user_id, ‘billing_first_name’, $firstname);
update_user_meta($user_id, ‘shipping_first_name’, $firstname);
update_user_meta($user_id, ‘billing_last_name’, $lastname);
update_user_meta($user_id, ‘shipping_last_name’, $lastname);
}The code works fine until Buddypress is activated. The it just reverts to the usual wordpress log in with only the profile fields that are shown in the “Profile Fields” tab on the wordpress dashboard.
I feel like I must be missing something obvious but it is driving me crazy! Any help would be enormously appreciated. Thanks!
- You must be logged in to reply to this topic.