Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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, 7 months ago by lyway1.
    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?

    Thread Starter lyway1

    (@lyway1)

    But this is the problem… I set individually some metas and titles, but they still get overwritten by Yoast…

    Thread Starter lyway1

    (@lyway1)

    Thank You!

    And I’m using a Plugin called Popups

    Thread Starter lyway1

    (@lyway1)

    Where can I do that? – On your website nothing is explained where it can be disabled

Viewing 5 replies - 1 through 5 (of 5 total)