What Is The Register Page On Woocommerce Wordpress Edit Page
To brainstorm, brand sure that the WooCommerce registration forms are enabled on the business relationship login folio. For this, go to WooCommerce > Settings > Accounts and check Enable customer registration on the "My account" folio.
After enabling this selection, yous tin can see the WooCommerce registration form at the frontend.
As should exist obvious information technology is a pretty modest WooCommerce grade, however, we can add more fields to this structure by utilizing the following actions. Soon, to include extra fields similar showtime name, last proper noun and telephone number, and so on, include the post-obit lines of code toward the cease of your functions.php, which is located in your theme folder.
function wooc_extra_register_fields() {?> <p class="form-row form-row-wide"> <label for="reg_billing_phone"><?php _e( 'Phone', 'woocommerce' ); ?></label> <input type="text" class="input-text" proper name="billing_phone" id="reg_billing_phone" value="<?php esc_attr_e( $_POST['billing_phone'] ); ?>" /> </p> <p form="form-row form-row-starting time"> <label for="reg_billing_first_name"><?php _e( 'Offset name', 'woocommerce' ); ?><bridge course="required">*</span></label> <input type="text" class="input-text" proper 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 course="form-row form-row-last"> <label for="reg_billing_last_name"><?php _e( 'Last name', 'woocommerce' ); ?><span course="required">*</bridge></characterization> <input blazon="text" form="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> <div course="articulate"></div> <?php } add_action( 'woocommerce_register_form_start', 'wooc_extra_register_fields' ); Now if you refresh the page, you'll see the fields being added to WooCommerce registration course.
To chronicle these registration course fields with the billing accost, you have to include the prefix "billing_" before the field name. The following is a list of all the valid WooCommerce course fields that can exist added to the registration form and tin can be associated with a billing address.
- billing_first_name
- billing_last_name
- billing_company
- billing_address_1
- billing_address_2
- billing_city
- billing_postcode
- billing_country
- billing_state
- billing_email
- billing_phone
At present we as well need to validate these newly added form fields. To validate these structure fields, include the accompanying lines of code toward the end of your functions.php file which located in the theme binder.
/** * register fields Validating. */ function wooc_validate_extra_register_fields( $username, $email, $validation_errors ) { if ( isset( $_POST['billing_first_name'] ) && empty( $_POST['billing_first_name'] ) ) { $validation_errors->add together( 'billing_first_name_error', __( '<strong>Mistake</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' ) ); } return $validation_errors; } add_action( 'woocommerce_register_post', 'wooc_validate_extra_register_fields', 10, iii ); On the off chance that you like into the code of this role, you'll make sense that it is simply checking $_POST array for class values and including an error message if a value is not present or invalid data.
Cloudways Platform is Congenital for WooCommerce Stores!
Over 55+ born features to amend evolution workflows and site speed.
Along these lines, you can besides include various validation rules and you likewise add validation rules to dissimilar fields besides. Y'all can see i of our custom validation rules being applied:
At long last, we need to save these values to the database.
To insert values in database add the post-obit part in your theme'south functions.php file:
/** * Below lawmaking 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'] ) ); } 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'] ) ); } if ( isset( $_POST['billing_last_name'] ) ) { // Last proper noun field which is by default update_user_meta( $customer_id, 'last_name', sanitize_text_field( $_POST['billing_last_name'] ) ); // Concluding name field which is used in WooCommerce update_user_meta( $customer_id, 'billing_last_name', sanitize_text_field( $_POST['billing_last_name'] ) ); } } add_action( 'woocommerce_created_customer', 'wooc_save_extra_register_fields' ); And we are done here! Now the recently added fields have been added, validated, and inserted for futurity use.
On the billing address folio in your account, you need to click on edit to get at that place. You can see the values from the registration grade already beingness populated.
WooCommerce Edit My Account Folio – An Culling Method
If you wish to use an alternative method for registering WoOCommerce form fields, you can use WooCommerce hooks to edit WooCommerce my account folio.
The following code snippet illustrates the procedure:
function woocommerce_edit_my_account_page() { render apply_filters( 'woocommerce_forms_field', array( 'woocommerce_my_account_page' => assortment( 'type' => 'text', 'characterization' => __( 'Socail Media Contour Link', ' cloudways' ), 'placeholder' => __( 'Contour Link', 'cloudways' ), 'required' => false, ), ) ); } office edit_my_account_page_woocommerce() { $fields = woocommerce_edit_my_account_page(); foreach ( $fields as $key => $field_args ) { woocommerce_form_field( $cardinal, $field_args ); } } add_action( 'woocommerce_register_form', 'edit_my_account_page_woocommerce', 15 ); Here's how the outcome of the snippet would look like:
The above snippet starts with the woocommerce_edit_my_account_page() that is used in the later part of the snippet. This function returns a multidimensional array that contains the information virtually the fields (blazon, characterization, placeholder, required or not) that y'all are adding to the form.
To ensure that the values of the fields tin can be updated further on, the assortment is further processes through the woocommerce_form_field() function.
in the next one-half of the snippet, I have used the edit_my_account_page_woocommerce() function. Every bit you tin can see the $fields variable contains the array generated by the woocommerce_edit_my_account_page() function. This is looped through using the foreach() loop.
Take a Chance With Cloudways
Attempt out the demo starting time earlier you decide.
Adding Your Required WooCommerce Form Field
As yous can see this above mentioned snippet is very flexible and you lot tin can add together any field type that you wish by providing the advisable field structure value in the $fields array.
Here are a few examples:
Textarea
'woocommerce_my_account_page' => array( 'type' => 'textarea', 'label' => __( 'Socail Media Profile Link', 'cloudways' ), 'placeholder' => __( 'Profile Link', 'cloudways' ), 'required' => faux, ),
checkbox
'woocommerce_my_account_page_checkbox' => array( 'blazon' => 'checkbox', 'label' => __( 'Checkbox', 'cloudways' ), ),
Option list
'woocommerce_my_account_page_select' => array( 'type' => 'select', 'label' => __( 'Select Field', 'cloudways' ), 'options' => array( '' => __( 'Select an options.', 'cloudways' ), 1 => __( 'WooCommerce forms', 'cloudways' ), 2 => __( 'WooCommerce my account folio', 'cloudways' ), 3 => __( 'WooCommerce edit my account page', 'cloudways' ), iv => __( 'How to edit WooCommerce my account page', 'cloudways' ), 5 => __( 'Edit my account page WooCommerce', 'cloudways' ), ),
Hither's how these options would look like in the form:
You tin can save these values in the function wooc_save_extra_register_fields(), mentioned above.
Q. How practice I show a registration grade in WooCommerce?
To do this go to WooCommerce → Settings → Accounts → Registration Options. Now hither y'all need to enable the option called "Enable registration on the "My Account" folio".
Q. How practice I display custom fields in WooCommerce?
For this you demand to install WooCommerce production tabular array plugin then go to WooCommerce → Settings → Products → Product Tables and choose the settings for your product tables. Open the 'Edit Product' screen for the product where you want to add together a table of custom fields. Add a product table shortcode to the Short Description field.
Q. How do I add product data to WooCommerce?
The Product Data meta box is where the majority of important information is added for your products. To do this go to WooCommerce → Products → Add New. Curlicue down the Product Data section. Here you can add your product detail.
Q. How to add CAPTCHA in WooCommerce registration form?
Get to WooCommerce Dashboard → Plugins → Add New, then search Captcha Recaptcha for WooCommerce after that install now this plugin and activate.
Conclusion
This tutorial allows the users to add extra WooCommerce class fields in registration page which is My Account page of WooCommerce. So, now you tin can add more fields other than firstname, lastname and contact fields. You may also make them mandatory fields.
I hope you found the commodity helpful. Permit me know in the comments if y'all've got whatever questions, and I'll get back to you!
Share your opinion in the comment section. COMMENT Now
Share This Commodity
Customer Review at
"Great operation for the price, and plenty of control"
Sean P [SMB Possessor]
Owais Alam
is the WordPress Community Manager at Cloudways - A Managed WooCommerce Hosting Platform and a seasoned PHP programmer. He loves to develop all sorts of websites on WordPress and is in love with WooCommerce in particular. You can e-mail him at [email protected]
What Is The Register Page On Woocommerce Wordpress Edit Page,
Source: https://www.cloudways.com/blog/add-woocommerce-registration-form-fields/
Posted by: williamsongeophy.blogspot.com

0 Response to "What Is The Register Page On Woocommerce Wordpress Edit Page"
Post a Comment