更改“我的帐户”为“用户名”WooCommerce侧栏

问题描述:

我想为用户显示一次登录,而不是默认的单词我的帐户我想显示用户的名称,我试过这个代码,但它不显示任何东西!更改“我的帐户”为“用户名”WooCommerce侧栏

似乎并不认可该文件中的变量$current_user位于:可湿性粉剂内容/主题/ THEMENAME /架构/功能/宇account.php

printf(__('%s', 'wpdance'),$current_user->user_lastname); 

是:

printf(__('My Account', 'wpdance')); 

而且我也尝试使用此代码来获得每一件事情:

<?php global $current_user; 
    get_currentuserinfo(); 

    echo 'Username: ' . $current_user->user_login . "\n"; 
    echo 'User email: ' . $current_user->user_email . "\n"; 
    echo 'User level: ' . $current_user->user_level . "\n"; 
    echo 'User first name: ' . $current_user->user_firstname . "\n"; 
    echo 'User last name: ' . $current_user->user_lastname . "\n"; 
    echo 'User display name: ' . $current_user->display_name . "\n"; 
    echo 'User ID: ' . $current_user->ID . "\n"; 

>

但是User first name:User last name:是空的!

有人有任何建议或想法吗?

谢谢先进!

+0

你尝试'的printf(__($ current_user-> user_lastname, 'wpdance')) ;'? – Peon

+0

我jst做到了,它不起作用! –

最好的办法是使用wp_get_current_user()(无需任何全局变量)以及确保用户已登录的条件:

if (is_user_logged_in()) { 
    $user_info = wp_get_current_user(); 
    $user_last_name = $user_info->user_lastname; 
    printf(__('%s', 'wpdance'), $user_last_name); 
} 

或用完整的名称:

if (is_user_logged_in()) { 
    $user_info = wp_get_current_user(); 
    $user_complete_name = $user_info->user_firstname . ' ' . $user_info->user_lastname; 
    printf(__('%s', 'wpdance'), $user_complete_name); 
} 

参考文献:

+0

感谢您分享您的答案,但它不显示任何内容! –

+0

错误是: '注意:Laméthodedu constructeurappeléepour WP_Widget dans mgwoocommercebrands_list_widget estobsolètedepuis la version 4.3.0! Utilisez __construct() àla place。 in /home/epicerymarket/public_html/wp-includes/functions.php on line 3718' 你有什么想法吗? –

+0

我得到你,你是对的,你的代码是一致的!所以我有另一个问题,我会发布有关它的新问题! –

尝试调用

global $current_user; 
get_currentuserinfo(); 

printf(__('%s', 'wpdance'),$current_user->user_lastname); 

https://codex.wordpress.org/Function_Reference/get_currentuserinfo#Examples

而且你确定的名字总是被设置?如果$current_user->ID至少返回一个值,可能您可以确保$current_user有效。

并启用您wp_config.php调试可以很好的帮助,以显示所有通知和错误:

define('WP_DEBUG', true); 

https://codex.wordpress.org/Debugging_in_WordPress

+0

感谢您的回答,我尝试过并发生了此错误: '注意:mgwoocommercebrands_list_widget中的WP_Widget的被调用构造方法自版本4.3.0开始已弃用!改为使用 __construct() 。在3718行的/home/classi33/public_html/wp-includes/functions.php“你有什么想法吗? –

+0

我认为这与它无关! –