• Resolved hadimargo

    (@hadimargo)


    hi, i want to create a new form for registration.
    but i need to put a box that it should take a phone number for his/her woocommerce account.
    so what is the shortcode of phone number in woocommerce?

    • This topic was modified 2 years, 11 months ago by hadimargo.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello @hadimargo,

    Copy the below code and insert in your theme’s functions.php. Alternatively you can use plugin like “Code snippet” in order to add it safely.

    The below code add a new phone number field on the WooCommerce registration form. The data will be saved as a billing phone number.

    function wooc_extra_register_fields() {?>
           <p class="form-row form-row-wide">
           <input type="text" class="input-text" name="billing_phone" placeholder="Phone number" id="reg_billing_phone" value="<?php esc_attr_e( $_POST['billing_phone'] ); ?>" />
           </p>
           <div class="clear"></div>
           <?php
     }
     add_action( 'woocommerce_register_form_start', 'wooc_extra_register_fields' );
    
    /**
    
    * register fields Validating.
    
    */
    
    function wooc_validate_extra_register_fields( $username, $email, $validation_errors ) {
    
          if ( isset( $_POST['reg_billing_phone'] ) && empty( $_POST['reg_billing_phone'] ) ) {
    
                 $validation_errors->add( 'reg_billing_phone_error', __( '<strong>Error</strong>: Phone number is required!', 'woocommerce' ) );
          }
    }
    
    add_action( 'woocommerce_register_post', 'wooc_validate_extra_register_fields', 10, 3 );
    
    /**
    * Below code save extra fields.
    */
    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'] ) );
              }
    }
    add_action( 'woocommerce_created_customer', 'wooc_save_extra_register_fields' );

    Hope this helps!
    Naz.

    Hi @hadimargo

    There is no ready to use shortcode for accepting the phone number in the registration form, but the following articles present some workarounds to help you achieve that:

    Also, we have the Registration & Login with Mobile Phone Number plugin in our marketplace that you can use:
    https://woocommerce.com/products/registration-login-with-mobile-phone-number/

    * For any pre-sales questions related to this plugin, please create a ticket here. You’d need to log into your WooCommerce account before you can access that page, or create an account if you do not have one. Just so you know, in the WooCommerce.com marketplace we offer a 30-day refund policy so you can test the extension and make sure it works for you.

    We’ve not heard back from you in a while, so I’m marking this thread as resolved. Hopefully, the above info was helpful.

    If you have further questions, please feel free to open a new topic.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Phone number Shortcode in woocommerce?’ is closed to new replies.