Home > Back-end >  Get author information in yith woocommerce wishlist premium
Get author information in yith woocommerce wishlist premium

Time:10-09

Hello I hope you can help me. I don't know much about PHP code. I am testing yith woocommerce wishlist premium plugin, and in wishlist-view.php file I have placed the following PHP code, but it only shows the information of the current user, not the author of the wishlist.

<?php
$current_user = wp_get_current_user();
echo 'Email: ' . $current_user->user_email . '<br />';
echo 'Name: ' . $current_user->user_firstname . '<br />';
echo 'LastName: ' . $current_user->user_lastname . '<br />';
?>

I would love to show the author information of the list. So when the list is shared by url, another user can see the user meta data of whoever created the whislist. The author meta data I would like to see is name (user_firstname), email (user_email) and profile picture (get_avatar)

I hope you can help me best regards

CodePudding user response:

You can get the wishlist user/author ID from the $wishlist object which is available in template files, then from that ID you can get the user data using the get_userdata function and you can print the information.

Here is the code:

<?php
// Get wishlist user/author ID.
$wishlist_user_id = $wishlist->get_user_id();

// Check if the user is not empty.
if ( ! empty( $wishlist_user_id ) ) {
    // Get wishlist user data.
    $wishlist_user = get_userdata( absint( $wishlist_user_id ) );
    // Check if a user is found.
    if ( ! empty( $wishlist_user ) ) {
        // Write the information.
        echo '<p>Email: ' . esc_html( $wishlist_user->user_email ) . '</p>';
        echo '<p>First Name: ' . esc_html( $wishlist_user->first_name ) . '</p>';
        echo '<p>Last Name: ' . esc_html( $wishlist_user->last_name ) . '</p>';
    }
}
  • Related