• I want to change the registration form of WooCommerce a little bit. I’m fine with the normal form which comes from WooCommerce but I want to add the following fields and functions:

    If a person enters the email and the password and press register, the person should be redirected to another page where the person is forced to enter the address, phone number and the full name. But how can I do that? I already googled but found nothing… Further, only if the person has entered the details, the confirmtion mail should be send. All that should also be safed with a recaptcher at the end.

    Does anybody has an idea how I can solve that?
    Would it be possible to redirect the person after entering the email and passwords details to a page where the person is supposed to enter the shipping details and only if those are entered the confirmtion mail gets sended?

    Kind Regards and Thank You!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi,

    You need to customize the registration process to be like that. I can’t do whole code for you here but I can give a direction on how you may proceed.If you are familiar with WooCommerce coding you should be able to get it done.

    Step  1 : remove the 'woocommerce_created_customer' action from $email actions using 'woocommerce_email_actions' filter so that the new customer email doesn't fire automatically.
    Step 2 : Use the 'woocommerce_created_customer' action to redirect to a custom template page where you have the extra fields form ready;
    Step 3: after processing the submission from step 2 you should send the email using WC_Emails.
     

    Thanks

    Thread Starter lyway1

    (@lyway1)

    I found now this one (https://www.cloudways.com/blog/add-woocommerce-registration-form-fields/) and implemented it like this. It its also working and I can see my custom WooCommerece fields. But they get displayed above the already existing WooCommerece email and password field. How can I display the custom fields below the already existing fields but above the WooCommerece register button?

    Use the woocommerce_register_form_end hook instead of woocommerce_register_form_start.

    Thread Starter lyway1

    (@lyway1)

    I have now other problem… I implemented everything and it is shown up exactly there where I want it. But nobody can register himself there…

    Not even if you just you the email and password field… How can that be?

    If you filled the fields and click on register, you can see in the console that the data get be send with $POST. But why doesn’t WooCommerce isn’t registering anybody anymore?

    I wrote echo Yes Address\n or for example echo Yes Phone\n which should be pop up if address or phone got be filled… But it doesn’t can anybody explain that to me…

    Here my code:

    function wooc_extra_register_fields() {
    ?>     
    <hr style="margin-top:20px;margin-bottom:5px;" class="woocommerce-expanding-custom-register-form">
    <p class="form-row form-row-first woocommerce-expanding-custom-register-form">
    <label for="reg_billing_first_name"><?php _e( 'First name', 'woocommerce' ); ?><span class="required">*</span></label>
    <input type="text" class="input-text" name="billing_first_name" id="reg_billing_first_name" value="<?php if ( ! empty( $_POST['billing_first_name'] ) ) esc_attr_e( $_POST['billing_first_name'] ); ?>" />
    </p>
    <p class="form-row form-row-last woocommerce-expanding-custom-register-form">
    <label for="reg_billing_last_name"><?php _e( 'Last name', 'woocommerce' ); ?><span class="required">*</span></label>
    <input type="text" class="input-text" name="billing_last_name" id="reg_billing_last_name" value="<?php if ( ! empty( $_POST['billing_last_name'] ) ) esc_attr_e( $_POST['billing_last_name'] ); ?>" />
    </p>
    <p class="form-row form-row-wide woocommerce-expanding-custom-register-form">
    <label for="reg_billing_phone"><?php _e( 'Phone', 'woocommerce' ); ?><span class="required">*</span></label>
    <input type="text" class="input-text" name="billing_phone" id="reg_billing_phone" value="<?php if ( ! empty( $_POST['billing_phone'] ) ) esc_attr_e( $_POST['billing_phone'] ); ?>" />
    </p>
    <p class="form-row form-row-wide woocommerce-expanding-custom-register-form">
    <label for="reg_billing_company"><?php _e( 'Company Name', 'woocommerce' ); ?></span></label>
    <input type="text" class="input-text" name="reg_billing_company" id="reg_billing_company" value="<?php esc_attr_e( $_POST['billing_company'] ); ?>" />
    </p>
    <p class="form-row form-row-wide woocommerce-expanding-custom-register-form">
    <label for="reg_billing_address_1"><?php _e( 'Address', 'woocommerce' ); ?><span class="required">*</span></label>
    <input type="text" class="input-text" name="reg_billing_address_1" id="reg_billing_address_1" value="<?php if ( ! empty( $_POST['billing_address_1'] ) ) esc_attr_e( $_POST['billing_address_1'] ); ?>" placeholder="Street Address" />
    </p>
    <p class="form-row form-row-wide woocommerce-expanding-custom-register-form">
    <input type="text" class="input-text" name="reg_billing_address_2" id="reg_billing_address_2" value="<?php esc_attr_e( $_POST['billing_address_2'] ); ?>" placeholder="Apartmant, Suite, Unit, etc. (optional)" />
    </p>
    <p class="form-row form-row-wide woocommerce-expanding-custom-register-form">
    <label for="reg_billing_city"><?php _e( 'Suburb', 'woocommerce' ); ?><span class="required">*</span></label>
    <input type="text" class="input-text" name="reg_billing_city" id="reg_billing_city" value="<?php if ( ! empty( $_POST['billing_city'] ) ) esc_attr_e( $_POST['billing_city'] ); ?>" />
    </p>
    <p class="form-row form-row-first woocommerce-expanding-custom-register-form">
    <label for="reg_billing_state"><?php _e( 'State', 'woocommerce' ); ?><span class="required">*</span></label>
    <select name="reg_billing_state" id="reg_billing_state" class="reg_billing_state" placeholder="Select a state…" value="<?php if ( ! empty( $_POST['billing_state'] ) ) esc_attr_e( $_POST['billing_state'] ); ?>">
    <option value="ACT">Australian Capital Territory</option>
    <option value="NSW">New South Wales</option>
    <option value="NT">Northern Territory</option>
    <option value="QLD">Queensland</option>
    <option value="SA">South Australia</option>
    <option value="TAS">Tasmania</option>
    <option value="VIC">Victoria</option>
    <option value="WA">Western Australia</option>
    </select>
    </p>
    <p class="form-row form-row-last woocommerce-expanding-custom-register-form">
    <label for="reg_billing_postcode"><?php _e( 'Postcode', 'woocommerce' ); ?><span class="required">*</span></label>
    <input type="text" class="input-text" name="reg_billing_postcode" id="reg_billing_postcode" value="<?php if ( ! empty( $_POST['billing_postcode'] ) ) esc_attr_e( $_POST['billing_postcode'] ); ?>" />
    </p>
    
    <?php
    }
    
    add_action( 'woocommerce_register_form_start', 'wooc_extra_register_fields' );
    
    function wooc_validate_extra_register_fields( $username, $email, $validation_errors ) {
    
          if ( isset( $_POST['billing_first_name'] ) && empty( $_POST['billing_first_name'] ) ) {
    
                 $validation_errors->add( 'billing_first_name_error', __( '<strong>Error</strong>: First name is required!', 'woocommerce' ) );
    
          }
    
          if ( isset( $_POST['billing_last_name'] ) && empty( $_POST['billing_last_name'] ) ) {
    
                 $validation_errors->add( 'billing_last_name_error', __( '<strong>Error</strong>: Last name is required!.', 'woocommerce' ) );
    
          }
    
          if ( isset( $_POST['billing_phone'] ) && empty( $_POST['billing_phone'] ) ) {
    
                 $validation_errors->add( 'billing_phone_error', __( '<strong>Error</strong>: Phone number is required!.', 'woocommerce' ) );
    
          }
    
          if ( isset( $_POST['billing_address_1'] ) && empty( $_POST['billing_address_1'] ) ) {
    
                 $validation_errors->add( 'billing_address_1_error', __( '<strong>Error</strong>: Address is required!.', 'woocommerce' ) );
    
          }
    
          if ( isset( $_POST['billing_city'] ) && empty( $_POST['billing_city'] ) ) {
    
                 $validation_errors->add( 'billing_city_error', __( '<strong>Error</strong>: Suburb is required!.', 'woocommerce' ) );
    
          }
    
          if ( isset( $_POST['billing_state'] ) && empty( $_POST['billing_state'] ) ) {
    
                 $validation_errors->add( 'billing_state_error', __( '<strong>Error</strong>: State is required!.', 'woocommerce' ) );
    
          }
    
          if ( isset( $_POST['billing_postcode'] ) && empty( $_POST['billing_postcode'] ) ) {
    
                 $validation_errors->add( 'billing_postcode_error', __( '<strong>Error</strong>: Postcode is required!.', 'woocommerce' ) );
    
          }
          
             return $validation_errors;
    }
    
    add_action( 'woocommerce_register_post', 'wooc_validate_extra_register_fields', 10, 3 );
    
    function wooc_save_extra_register_fields( $customer_id ) {
        if ( isset( $_POST['billing_phone'] ) ) {
            // Phone input filed which is used in WooCommerce
            update_user_meta( $customer_id, 'billing_phone', sanitize_text_field( $_POST['billing_phone'] ) );
    
            echo 'Yes Phone\n';
        }
    
        if ( isset( $_POST['billing_first_name'] ) ) {
            //First name field which is by default
            update_user_meta( $customer_id, 'first_name', sanitize_text_field( $_POST['billing_first_name'] ) );
            // First name field which is used in WooCommerce
            update_user_meta( $customer_id, 'billing_first_name', sanitize_text_field( $_POST['billing_first_name'] ) );
    
            echo 'Yes Name\n';
        }
    
        if ( isset( $_POST['billing_last_name'] ) ) {
            // Last name field which is by default
            update_user_meta( $customer_id, 'last_name', sanitize_text_field( $_POST['billing_last_name'] ) );
            // Last name field which is used in WooCommerce
            update_user_meta( $customer_id, 'billing_last_name', sanitize_text_field( $_POST['billing_last_name'] ) );
    
            echo 'Yes Last\n';
        }
    
        if ( isset( $_POST['billing_company'] ) ) {
            update_user_meta( $customer_id, 'billing_company', sanitize_text_field( $_POST['billing_company'] ) );
    
            echo 'Yes Company\n';
        }
    
        if ( isset( $_POST['billing_address_1'] ) ) {
            update_user_meta( $customer_id, 'billing_address_1', sanitize_text_field( $_POST['billing_address_1'] ) );
    
            echo 'Yes Address1\n';
        }
    
        if ( isset( $_POST['billing_address_2'] ) ) {
            update_user_meta( $customer_id, 'billing_address_2', sanitize_text_field( $_POST['billing_address_2'] ) );
    
            echo 'Yes Address2\n';
        }
    
        if ( isset( $_POST['billing_city'] ) ) {
            update_user_meta( $customer_id, 'billing_city', sanitize_text_field( $_POST['billing_city'] ) );
    
            echo 'Yes City\n';
        }
    
        if ( isset( $_POST['billing_state'] ) ) {
            update_user_meta( $customer_id, 'billing_state', sanitize_text_field( $_POST['billing_state'] ) );
    
            echo 'Yes State\n';
        }
        
        if ( isset( $_POST['billing_postcode'] ) ) {
            update_user_meta( $customer_id, 'billing_postcode', sanitize_text_field( $_POST['billing_postcode'] ) );
    
            echo 'Yes Postcode\n';
        }
    }
    
    add_action( 'woocommerce_created_customer', 'wooc_save_extra_register_fields' );
    ?>

    Would be very thankful for help!

    • This reply was modified 7 years, 4 months ago by lyway1.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Change WooCommerce registration form/way?’ is closed to new replies.