• Resolved jftb

    (@jftb)


    I was wondering if you can help me (I’m not sure if it’s you or WooCommerce I need to talk to).

    For a user that accesses ‘my account’ who is new to the site and wants to log in, I want to edit the ‘registration’ fields at the bottom of this standard shortcode section to include phone number – or simply a link to a bespoke registration form that I have created.

    Do you happy to know how I do this? All help gratefully received!!!

    Thanks
    Jen

Viewing 1 replies (of 1 total)
  • Plugin Author Nitesh

    (@nitesh_singh)

    Hi Jen,

    Sorry for delayed reply.

    My Account is a page served by WooCommerce and I’m sure there might be plenty of free plugins which adds fields to this page. You can also ask WooCommerce this question.

    You can though add following code in theme’s functions.php.

    Step 1: Hook to display a new field in WooCommerce Register Form

    add_action( 'woocommerce_register_form', 'ctm_function_wc_register_form' );  
    	function ctm_function_wc_register_form(){
    	global $woocommerce;
    	?>
    	   <div class="clear"></div>
    	   <p class="form-row form-row-wide">
    	   <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>
    	}

    Step 2: Add below code if you want that field to be a mandatory field.

    add_filter( 'woocommerce_registration_errors', ctm_function_wc_register_form1,10, 3);
      function ctm_function_wc_register_form1($errors, $username, $email){	
    							if ( isset( $_POST['billing_phone'] ) && empty( $_POST['billing_phone'] ) ) {
    					$errors->add( 'billing_phone_error', __( '<strong>Billing Phone</strong>:  is a required field', 'woocommerce' ) );
    				}
    				return $errors;
    			}

    Step 3: Code to save the data in user meta data

    add_action( 'woocommerce_created_customer', ctm_function_wc_register_form3,10, 3);
    	function ctm_function_wc_register_form3( $customer_id ) {
    				if ( isset( $_POST['billing_phone'] ) ) {
    					update_user_meta( $customer_id, 'billing_phone', sanitize_text_field( $_POST['billing_phone'] ) );					
    				}
    			}

    Regards,
    Nitesh

Viewing 1 replies (of 1 total)

The topic ‘Registration Support’ is closed to new replies.