Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

I have two fields that I want to merge into one meta value.

$
0
0

Replies: 0

Hi everyone I’m going for advice.
I have created a custom field in the registration where I have a phone number and a select for selecting a preset added via JS. I would like to ask how do I get the area code so that it is stored next to the number ??
I created in office

add_action ('user_register', 'myplugin_user_register');
function myplugin_user_register ($ country_code) {
     if (! empty ($ _POST ['country_code'])) {
         update_user_meta ($ country_code, 'country_code', sanitize_text_field ($ _POST ['country_code']));
     }
} 

I have two fields that I want to merge into one meta value. a country_code field that is custom field and a second phone field that is created automatically via WCFM

new code

add_action( 'user_register', 'myplugin_user_register', 10, 1 );
function myplugin_user_register( $user_id ) {
    if ( isset( $_POST['country_code'] ) && isset( $_POST['wcfmvm_static_infos[phone]'] ) ) {
        $country_code = $_POST['country_code'];
        $phone = sanitize_text_field($_POST['wcfmvm_static_infos[phone]']);
        $billing_phone = $country_code.' '.$phone;
        update_user_meta( $user_id, 'billing_phone', $billing_phone );
    }
}

Viewing all articles
Browse latest Browse all 59525

Trending Articles