AI Verified

Name

Display the mobile phone field

Language

PHP

Rating

Voted: 0 by 0 user(s)

Codevault

jbeer

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: Not Specified

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

14/11/2022

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Display the mobile phone field

 
                    
1add_action( 'woocommerce_edit_account_form', 'add_billing_mobile_phone_to_edit_account_form' ); // After existing fields
2function add_billing_mobile_phone_to_edit_account_form() {
3 $user = wp_get_current_user();
4 ?>
5 <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
6 <label for="billing_mobile_phone"><?php _e( 'Telefon', 'woocommerce' ); ?> <span class="required">*</span></label>
7 <input type="text" class="woocommerce-Input woocommerce-Input--phone input-text" name="billing_mobile_phone" id="billing_mobile_phone" value="<?php echo esc_attr( $user->billing_mobile_phone ); ?>" />
8 </p>
9 <?php
10}
11 
12// Check and validate the mobile phone
13add_action( 'woocommerce_save_account_details_errors','billing_mobile_phone_field_validation', 20, 1 );
14function billing_mobile_phone_field_validation( $args ){
15 if ( isset($_POST['billing_mobile_phone']) && empty($_POST['billing_mobile_phone']) )
16 $args->add( 'error', __( 'Bitte trage deine Telefonnummer ein', 'woocommerce' ),'');
17}
18 
19// Save the mobile phone value to user data
20add_action( 'woocommerce_save_account_details', 'my_account_saving_billing_mobile_phone', 20, 1 );
21function my_account_saving_billing_mobile_phone( $user_id ) {
22 if( isset($_POST['billing_mobile_phone']) && ! empty($_POST['billing_mobile_phone']) )
23 update_user_meta( $user_id, 'billing_mobile_phone', sanitize_text_field($_POST['billing_mobile_phone']) );
24}

0

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

AI Verified

0

Subscription starts @ 25. of the month

Added: 1 year ago

Last Updated: 1 year ago

WooCommerce

AI Verified

0

WooCommerce autoselect Free shipping if available

Added: 1 year ago

Last Updated: 1 year ago

WooCommerce

AI Verified

0

Add new orders status

Added: 1 year ago

Last Updated: 1 year ago

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WooCommerce

AI Verified

3

Confirm Password Field in Woocommerce

Added: 1 year ago

Last Updated: 1 day ago

WooCommerce

AI Verified

3

Redirect customers to own thank-you page after order

Added: 1 year ago

Last Updated: 1 day ago

You may want to redirect your customers to a custom thank you page after they place an order. You can do that with the following WooCommerce snippet

WooCommerce

AI Verified

2

Bypass logout confirmation.

Added: 1 year ago

Last Updated: 1 month ago