Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

Viewing 19 replies - 1 through 19 (of 19 total)

  • VersGemerkt
    Participant

    @stilld

    If you are interested: i posted the question here: https://thimpress.com/forums/topic/how-to-call-the-user-id/


    VersGemerkt
    Participant

    @stilld

    Ok, I’ll try that!


    VersGemerkt
    Participant

    @stilld

    I’ve found multiple lines with user_ID in order.php. Is this the way LearnPress calls the ID of the user? If so, how do I integrate this in my code?

    Another thing I found was this: _learn_press_customer_id. Is this something I can work with?


    VersGemerkt
    Participant

    @stilld

    Hi Shane, nice to hear from you again 🙂

    You are probably totally right, but I just don’t have the knowledge how to do the things you ask.. Could you give me any assistance? What do you need so you can help me out?

    David


    VersGemerkt
    Participant

    @stilld

    Hi!

    Can somebody help me out with this one? I’m really stuck now…

    Hope you all had a nice holiday!


    VersGemerkt
    Participant

    @stilld

    Yeah, it does show some actual user data, but this is called a different way. I’m talking like the field that displays the emailadress, which is not a custom field. This one is called in order.php like this: echo 'User email: ' . $user->user_email . '<br />';

    While the custom fields are called like this: do_action ( 'user_a_field' );


    VersGemerkt
    Participant

    @stilld

    Jigesh,

    Thanks for the help! This is how it looks right now:

    Screenshot order.php

    As you can see to the right of the profile image their are some data showing from the custom fields. @mcUK and @shanebp helped me out achieving this. BUT, this is not the correct data it should be showing for this user… It shows data that the logged in user filled in.

    I logged in as the user that filled in the correct data, and then it’s showing the right data for the user. But this is because I’m logged in as that user…

    Screen

    NOTE: I’m transferring this data across two plugins: buddypress and learnpress. Just so you know!

    This is the php in bp-custom:

    <?php
    
    function bptest_show_a_field () {
    	$user_id = bp_loggedin_user_id();
    	$firstname = xprofile_get_field_data( 'First Name', bp_loggedin_user_id(), $multi_format = 'comma' );
    	$lastname = xprofile_get_field_data( 'Last Name', bp_loggedin_user_id(), $multi_format = 'comma' );
    	$birth = xprofile_get_field_data( 'Date of birth', bp_loggedin_user_id(), $multi_format = 'comma' );
    	$education = xprofile_get_field_data( 'Highest Education Grade', bp_loggedin_user_id(), $multi_format = 'comma' );
    	$profession = xprofile_get_field_data( 'Profession', bp_loggedin_user_id(), $multi_format = 'comma' );
     
    	if ( ! $firstname && ! $lastname && ! $birth && ! $education && ! $profession ) { 
    	   return; 
    	}   
    	else {
    	    echo 'Voornaam: ' . $firstname . '<br />' ; 
    	    echo 'Achternaam: ' . $lastname . '<br />' ; 
    	    echo 'Geboortedatum: ' . $birth . '<br />' ; 
    	    echo 'Hoogste graad: ' . $education . '<br />' ; 
    	    echo 'Beroep: ' . $profession . '<br />' ; 
            
    	}
    }
    
    add_action ( 'user_a_field', 'bptest_show_a_field' );
    ?>
     

    VersGemerkt
    Participant

    @stilld

    Hi Jigesh!

    Thanks for the info!

    What I’m trying to achieve is that I need to be able to view the fields that are filled in by any random user who placed a order.

    At this moment the code doesn’t show the data filled in by the user I select, but the data that is filled in by me (the one who is logged in).

    I need to be able to open a order and view the data a user filled in the custom register form and not the data that I filled in (the current logged in user).

    I hope you understand my question!


    VersGemerkt
    Participant

    @stilld

    Hi!

    Is anyone able to help me out with this one?

    David


    VersGemerkt
    Participant

    @stilld

    I’ve found bp_displayed_user_id(), but the code won’t display any values when I replace every bp_loggedin_user_id() with bp_displayed_user_id()


    VersGemerkt
    Participant

    @stilld

    Ah, thanks! That works great!

    Now I’m running in a more serious issue… I discovered that all the code is working, but I’m using it to display data filled in by users in the backend of WordPress (order.php). BUT the code is only showing the filled in data from the user that is logged, while I need to be able to see the data filled in by every individual user that filled in the form.

    I hope you understand what I’m aiming for!

    David

    EDIT: I think it has something to do with this line:
    $user_id = bp_loggedin_user_id();


    VersGemerkt
    Participant

    @stilld

    Got one question now that I’m working with the provided code:

    Do you have tips for using this code for multiple custom fields? How should I edit this code in bp-custom.php if I want to add multiple custom fields?

    <?php
    
    function bptest_show_education_field () {
    	$user_id = bp_loggedin_user_id();
    	$education_field = xprofile_get_field_data( 'Highest Education Grade', bp_loggedin_user_id(), $multi_format = 'comma' );
    	if ( ! $education_field  ) { 
    	   return; 
    	}   
    	else {
            echo 'Hoogste opleiding: ' . $education_field . '<br />'; 
    	}
    }
    add_action ( 'user_education_field', 'bptest_show_education_field' );
    ?>

    I’m now trying to copy this code for every custom field, but that’s not really a clean way of doing this. And it’s not working either. Hope you can help me out with this one as well!


    VersGemerkt
    Participant

    @stilld

    And thanks to you as well mcUK!

    Thanks for all the help! So far it’s working great 😉


    VersGemerkt
    Participant

    @stilld

    @mcUK

    THIS WORKED 🙂 I’ll try and implement this with more field and get back to you when I run into problems, but for now this is working great! Thank you so much for your time and effort!


    VersGemerkt
    Participant

    @stilld

    Hi Shane,

    I’m sorry… I think I just don’t understand how you are implementing the code. Can you tell me where I should copy which code from your suggestion so I can call the custom field across plugins and outside the context of the members loop?

    For your info: order.php looks like this right now, with the do_action added.

    <h2 class="user-display-name">
    <?php
                                     
       $current_user = wp_get_current_user();
    
                                    echo 'Username: ' . $user->user_login . '<br />';
                                    echo 'User email: ' . $user->user_email . '<br />';
                                    echo 'Name: ' . $user->display_name . '<br />';
                                    echo 'Opleiding: ' . do_action ( 'user_opleiding_field' ); 
    
                                    //echo 'User ID: ' . $user->ID . '<br />';
                              //  ?>
                                 
                      
                            </h2> 

    VersGemerkt
    Participant

    @stilld

    I’M MAKING PROGRESS!!

    mcUK suggestion to test the code in Buddypress was a very good tip. This is what I found out:

     <div id="user-opleiding">
    <?php 
    do_action ( 'user_opleiding_field' ); 
    ?>
    </div>

    WORKS IN BUDDYPRESS 🙂 I added this do_action in the standard profile page, and it is showing the field Opleiding.

    Every other suggestion, like xprofile_get_field_data, doesn’t work.

    NOW: do one of you know how I can let do_action work when I call it from another plugin? That would be awesome!


    VersGemerkt
    Participant

    @stilld

    Hi Shanebp!

    Yeah, I tried the xprofile_get_field_data suggestion, but this also doesn’t work for me…

    I’ve got this in bp-custom.php:

    <?php
    
    //Add Location field to header if user has entered data into it
    //Nothing is shown if user hasn't entered anything into field
    function bptest_show_opleiding_field () {
    	$opleiding_field = bp_get_member_profile_data( 'field=Opleiding' ); 
    	if ( ! $opleiding_field  ) { 
    	   return; 
    	}   
    	else {
    	   echo '<span class="custom-field-text">' . $opleiding_field . '</span>'; 
    	}
    }
    //user_bio_location_field is used within the member-header php template file
    add_action ( 'user_opleiding_field', 'bptest_show_opleiding_field' );
    
    ?>
    

    and this in order.php in the Learnpress plugin:

    <div id="user-opleiding">
    Opleiding: <?php 
    $user_id = bp_loggedin_user_id();
    $opleiding_field = xprofile_get_field_data( 'Opleiding', bp_loggedin_user_id(), $multi_format = 'comma' );
    ?>
    </div>

    I looked at the url you have send, but I am not able to figure out how to use this, unfortunately. Maybe you have another suggestion for me to try?

    Sorry if I’m bordering you guys too much! I hope you are able to figure this one out with me 🙂 It would mean a lot!

    David


    VersGemerkt
    Participant

    @stilld

    Thanks for the quick reply!

    Ohhhh, I think I know why it’s not working. It’s because order.php is in de Learnpress plugin, and trying to get data from Buddypress. I’m not using your code inside Buddypress only…

    So: order.php in the Learnpress plugin needs to pull the data from the Buddypress plugin. When I change

    Opleiding: <?php
    do_action ( 'user_opleiding_field' ); 
    ?>

    in order.php to your new suggestion it doesn’t work either. Should your new suggestion work with a secondairy plugin (Learnpress?).

    Sorry if I’m asking dumb questions. I’m do have some PHP knowledge, but not enough to figure this kind of stuff out myself. I hope you can help us out!

    David


    VersGemerkt
    Participant

    @stilld

    Hi mcUK!

    Thanks for you reply. I’m working with Lotte on this issue.

    I tried adding your code. Everything should be in place right now, but it’s still not showing the custom fields. I’m probably using the code wrong…

    I tested your code with a custom field ‘Opleiding’ which I added in WordPress: Users -> Profile fields:

    Screenshot with the custom field

    I added this to bp-custom.php:

    <?php
    
    function bptest_show_opleiding_field () {
    	$opleiding_field = bp_get_member_profile_data( 'field=Opleiding' ); 
    	if ( ! $opleiding_field  ) { 
    	   return; 
    	}   
    	else {
    	   echo '<span class="custom-field-text">' . $opleiding_field . '</span>'; 
    	}
    }
    
    add_action ( 'user_opleiding_field', 'bptest_show_opleiding_field' );
    ?>

    Then I added this to order.php (the php file where the custom field should pop-up):

     <div id="user-opleiding">
    	                           <?php 
    		                          do_action ( 'user_opleiding_field' ); 
    	                           ?>
                                 </div>

    What am I doing wrong? It’s probably a typo or a wrongly added term… But I can’t figure out what it is!

    Hope you can help us out! Thanks for the help so far!

    David

Viewing 19 replies - 1 through 19 (of 19 total)
Skip to toolbar