0

currently I am developing a site using the Dokan multivendor plugin. I added a custom field in the registration form and

The below code is being used to add the custom field in the registration form

<p class="form-row form-group form-row-wide">
    <label for="tskypeid"><?php _e( 'Skype ID', 'dokan-lite' ); ?> <span class="required">*</span></label>
    <input type="text" class="input-text form-control" name="tskypeid" id="tskype-id" value="<?php if ( ! empty( $postdata['tskypeid'] ) ) echo esc_attr($postdata['tskypeid']); ?>" required="required" />
</p>

This is code that is being used to save the field data:

// save skype id after registration

function ms_dokan_on_create_seller( $user_id, $data ) {
    if ( $data['role'] != 'seller' ) {
        return;
    }

    $dokan_settings = array(
        'tskypeid'          => $_POST['tskypeid'],
    );

    update_user_meta( $user_id, 'dokan_profile_settings', $dokan_settings );
    update_user_meta( $user_id, 'dokan_store_name', $dokan_settings['store_name'] );

    do_action( 'dokan_new_seller_created', $user_id, $dokan_settings );
}

add_action( 'woocommerce_created_customer', 'ms_dokan_on_create_seller', 10, 2);

tried to access the value using the below code:

function wc_vendors_name_loop( $store_id ) {
    $user_id    = get_current_user_id();
    $dokan_profile_settings = get_user_meta( $user_id ) 
    ['dokan_profile_settings'];
    echo "<pre>";
    var_dump( $dokan_profile_settings );
    echo "</pre>";
}
add_action( 'wp_footer', 'wc_vendors_name_loop' );

This code outputs the below result:

array(1) {
    [0]=>
    string(1183) 
    "a:17:{
        s:8:"tskypeid";
        s:7:"asdfasd";
        s:10:"store_name";
        s:17:"asdfas dfasdfasdf";
        s:9:"store_ppp";
        i:0;s:7:"address";
        a:6:{
            s:8:"street_1";
            s:19:"fasdf asdf asdf sad";
            s:8:"street_2";
            s:15:"sadf asdf asd f";
            s:4:"city";
            s:10:"asdf asd f";
            s:3:"zip";
            s:8:"sad fsad";
            s:7:"country";
            s:2:"AZ";
            s:5:"state";
            s:9:"asdfasdf ";
        }
        s:8:
        "location";
        s:0:"";
        s:12:"find_address";
        s:27:"dsfas sadf sadfsadfsadf asf";
        s:6:"banner";
        i:0;s:5:"phone";
        s:9:"345346456";
        s:10:"show_email";
        s:3:"yes";
        s:14:"show_more_ptab";
        s:3:"yes";
        s:8:"gravatar";
        i:0;s:10:"enable_tnc";
        s:2:"on";
        s:9:"store_tnc";
        s:27:"asdf asdf asdfa sdf sadfsdf";
        s:18:"profile_completion";
        a:6:{
            s:5:"phone";
            i:10;s:10:"store_name";
            i:10;s:7:"address";
            i:10;s:9:"next_todo";
            s:31:"Add Banner to gain 15% progress";
            s:8:"progress";
            i:30;s:13:"progress_vals";
            a:8:{
                s:10:"banner_val";
                i:15;s:19:"profile_picture_val";
                i:15;s:14:"store_name_val";
                i:10;s:10:"social_val";
                a:5:{
                    s:2:"fb";
                    i:2;s:5:"gplus";
                    i:2;s:7:"twitter";
                    i:2;s:7:"youtube";
                    i:2;s:8:"linkedin";
                    i:2;
                }
                s:18:"payment_method_val";
                i:15;s:9:"phone_val";
                i:10;s:11:"address_val";
                i:10;s:7:"map_val";
                i:15;
            }
        }
        s:23:"show_min_order_discount";
        s:2:"no";
        s:28:"setting_minimum_order_amount";
        s:0:"";
        s:24:"setting_order_percentage";
        s:0:"";
    }"
}

Here I want to access the value of "tskypeid" in line 5 and the value is "asdfasd" in line 6

Please tell me how can I access that value.

Any help will be greatly appreciated.

Thank you in advance.

2

If you're asking how to get those meta keys via WordPress, you can use the get_user_meta() - https://codex.wordpress.org/Function_Reference/get_user_meta

get_user_meta( $user_id, 'tskypeid', true )

  • Thank you for the response. I tried using get_user_meta( $user_id, 'tskypeid', true ) but it returns string(0) "" butit should return "asdfasd". Can you help me out fixing this??? – M.S Shohan Mar 27 '18 at 13:09
  • How is this data being saved - can you add that code to the question? – Welcher Mar 27 '18 at 13:10
  • I have edited the question. Please check it. Waiting for your reply. Thank you. – M.S Shohan Mar 27 '18 at 13:19
  • The actual key is dokan_profile_settings and tskypeid is an element of that array. So you'd need to $data = get_user_meta( $user_id, 'tskypeid', true ) then echo $data['tskypeid']. – Jacob Peattie Mar 27 '18 at 13:22
  • I edited the code with your instruction like this and it's returning illegal string offset error. Please let me know my mistake. Thank you for your efforts of helping me find out the issue. function wc_vendors_name_loop( $store_id ) { $user_id = get_current_user_id(); $dokan_profile_settings = get_user_meta( $user_id, 'tskypeid', true ); echo "<pre>"; echo $dokan_profile_settings['tskypeid']; echo "</pre>"; } add_action( 'wp_footer', 'wc_vendors_name_loop' ); – M.S Shohan Mar 27 '18 at 13:29
0

Woohoo! I got it fixed with this code. function

wc_vendors_name_loop() { 
    $store_id = dokan_get_current_user_id(); 
    $existing_dokan_settings = get_user_meta( $store_id, 'dokan_profile_settings', true ); 
    echo $existing_dokan_settings['tskypeid']; 
} 
add_action( 'wp_footer', 'wc_vendors_name_loop' ); 

Now I can display the skype id in the front end.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.