[英]Hidden checkout field Woocommerce for current user
I would like to collect and save Wordpress profile photo of the current user who submits checkout form in Woocommerce. 我想收集并保存在Woocommerce中提交结帐表格的当前用户的Wordpress个人资料照片。 I would achieve this with hidden checkout field.
我可以通过隐藏的结帐字段来实现。 Here is what I have so far.
这是我到目前为止所拥有的。 Not sure how to get profile photo of the current user and output hidden photo :
不确定如何获取当前用户的个人资料照片并输出隐藏的照片:
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
}
All you need to do is pass the current users email address into the get_avatar() function. 您需要做的就是将当前用户的电子邮件地址传递给get_avatar()函数。
<?php
$current_user = wp_get_current_user();
if ( ($current_user instanceof WP_User) ) {
echo get_avatar( $current_user->user_email, 32 );
}
?>
Here are some links for specifics: 以下是一些具体链接:
get_avatar(); get_avatar(); wp_get_current_user();
wp_get_current_user();
To output the profile picture 输出个人资料图片
<?php
echo '<img src="'. get_the_author_meta( 'user_custom_avatar', $current_user->ID, 32 ) .'" />';
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.