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
My Answer:
To get the author information of the wishlist in YITH WooCommerce Wishlist Premium, you can use the following code:
php
global $wpdb;
$wishlist_id = get_query_var('wishlist_id');
$author_id = $wpdb->get_var("SELECT user_id FROM {$wpdb->prefix}yith_wcwl WHERE wishlist_token = '$wishlist_id'");
$author_info = get_userdata($author_id);
echo 'Email: ' . $author_info->user_email . '
';
echo 'Name: ' . $author_info->first_name . '
';
echo 'LastName: ' . $author_info->last_name . '
';
echo 'Profile Picture: ' . get_avatar($author_info->ID) . '
';
This code will retrieve the author ID of the wishlist based on the wishlist token and then fetch the user data using `get_userdata()` function. Finally, it will display the author's email, first name, last name, and profile picture using the retrieved user data.
Make sure to replace `{$wpdb->prefix}yith_wcwl` with the correct table name if it's different in your database. Also, ensure that this code is placed in the appropriate location within the wishlist-view.php file to display the author information correctly.
Rate this post
4 of 5 based on 9391 votesComments