【问题标题】:Hidden checkout field Woocommerce for current user当前用户的隐藏结帐字段 Woocommerce
【发布时间】:2017-07-06 07:07:15
【问题描述】:

我想收集并保存在 Woocommerce 中提交结帐表单的当前用户的 Wordpress 个人资料照片。我会通过隐藏的结帐字段来实现这一点。这是我到目前为止所拥有的。不知道如何获取当前用户的头像并输出隐藏照片:

  add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_hidden_field', 10, 1 );
    function my_custom_checkout_hidden_field( $checkout ) {

        // Get an instance of the current user object
        $user = wp_get_current_user();

       // Profile photo

       // Output hidden photo

}

【问题讨论】:

    标签: php wordpress woocommerce hook-woocommerce


    【解决方案1】:

    您需要做的就是将当前用户的电子邮件地址传递给 get_avatar() 函数。

    <?php 
    
    $current_user = wp_get_current_user();
    
    if ( ($current_user instanceof WP_User) ) {
        echo get_avatar( $current_user->user_email, 32 );
    }
    
    ?>
    

    这里有一些具体的链接:

    get_avatar(); wp_get_current_user();

    输出头像

    <?php 
    
    echo '<img src="'. get_the_author_meta( 'user_custom_avatar', $current_user->ID, 32 ) .'" />';
    
    ?>
    

    【讨论】:

    • 如果有用则表示请点赞..如果正确答案表示请输入正确答案...谢谢..
    猜你喜欢
    • 2015-07-09
    • 2017-07-25
    • 2017-07-22
    • 2018-07-05
    • 2019-01-21
    • 2021-02-08
    • 2020-02-09
    • 2021-10-27
    • 2021-07-23
    相关资源
    最近更新 更多