预填充字段 - WordPress 平台上的 Freshdesk
Prepopulating fields - Freshdesk on WordPress platform
我在我的 WordPress 网站上嵌入了一个 freshdesk 小部件。
当用户登录到 WordPress 网站时,我需要使用来自 WordPress 的用户凭据预填充电子邮件字段。到目前为止,我自己或在支持下都没有运气。有人知道 WordPress 如何存储用户电子邮件以及如何从 WordPress 获取它吗?
这是我当前的代码:
<script src="http://assets.freshdesk.com/widget/freshwidget.js" type="text/javascript"></script>
<script type="text/javascript">
FreshWidget.init("", {"queryString": "&helpdesk_ticket[requester]={{user.email}}&helpdesk_ticket[subject]={{user.subject}}&helpdesk_ticket[custom_field][phone_number]={{user.phone}}&helpdesk_ticket[custom_field][product_id]={{helpdesk.product}}",
"widgetType": "popup", "buttonType": "text", "buttonText": "Support",
"buttonColor": "white", "buttonBg": "#338700", "alignment": "4",
"offset": "235px", "formHeight": "500px",
"url": "http://xxxxxx.freshdesk.com"} );
</script>
首先获取用户 ID 此功能内置于 wordpress 中用于其他用途
function get_current_user_id() {
if ( ! function_exists( 'wp_get_current_user' ) )
return 0;
$user = wp_get_current_user();
return ( isset( $user->ID ) ? (int) $user->ID : 0 );
}
然后在自己的模板页面调用函数
<?php $user_info = get_userdata(get_current_user_id());
$email = $user_info->user_email;
?>
您可以使用 php jquery
的组合
$input = $("your input selector");
$input.attr("value","<?php echo $email; ?>");
来自 Ref first, Ref Second
最后找到你要预填充的字段并用$email 填充值属性。我建议 jQuery,而不是修改插件,因为更新可能会清除您所做的任何更改。
让我们首先获取当前用户的电子邮件地址(如果已登录)。
<?php
$user_id = get_current_user_id();
$email = '';
if ($user_id > 0) {
$user_info = get_userdata($user_id);
$email = $user_info->user_email;
}
?>
然后您可以嵌入 Freshdesk 反馈小部件代码以包含上述电子邮件。
<script src="http://assets.freshdesk.com/widget/freshwidget.js" type="text/javascript"></script>
<script type="text/javascript">
FreshWidget.init("", {
"queryString": "&helpdesk_ticket[requester]=<?= urlencode($email) ?>",
"widgetType": "popup", "buttonType": "text",
"buttonText": "Support",
"buttonColor": "white", "buttonBg": "#338700",
"alignment": "4",
"offset": "235px", "formHeight": "500px",
"url": "http://xxxxxx.freshdesk.com"} );
</script>
我在我的 WordPress 网站上嵌入了一个 freshdesk 小部件。
当用户登录到 WordPress 网站时,我需要使用来自 WordPress 的用户凭据预填充电子邮件字段。到目前为止,我自己或在支持下都没有运气。有人知道 WordPress 如何存储用户电子邮件以及如何从 WordPress 获取它吗?
这是我当前的代码:
<script src="http://assets.freshdesk.com/widget/freshwidget.js" type="text/javascript"></script>
<script type="text/javascript">
FreshWidget.init("", {"queryString": "&helpdesk_ticket[requester]={{user.email}}&helpdesk_ticket[subject]={{user.subject}}&helpdesk_ticket[custom_field][phone_number]={{user.phone}}&helpdesk_ticket[custom_field][product_id]={{helpdesk.product}}",
"widgetType": "popup", "buttonType": "text", "buttonText": "Support",
"buttonColor": "white", "buttonBg": "#338700", "alignment": "4",
"offset": "235px", "formHeight": "500px",
"url": "http://xxxxxx.freshdesk.com"} );
</script>
首先获取用户 ID 此功能内置于 wordpress 中用于其他用途
function get_current_user_id() {
if ( ! function_exists( 'wp_get_current_user' ) )
return 0;
$user = wp_get_current_user();
return ( isset( $user->ID ) ? (int) $user->ID : 0 );
}
然后在自己的模板页面调用函数
<?php $user_info = get_userdata(get_current_user_id());
$email = $user_info->user_email;
?>
您可以使用 php jquery
的组合 $input = $("your input selector");
$input.attr("value","<?php echo $email; ?>");
来自 Ref first, Ref Second
最后找到你要预填充的字段并用$email 填充值属性。我建议 jQuery,而不是修改插件,因为更新可能会清除您所做的任何更改。
让我们首先获取当前用户的电子邮件地址(如果已登录)。
<?php
$user_id = get_current_user_id();
$email = '';
if ($user_id > 0) {
$user_info = get_userdata($user_id);
$email = $user_info->user_email;
}
?>
然后您可以嵌入 Freshdesk 反馈小部件代码以包含上述电子邮件。
<script src="http://assets.freshdesk.com/widget/freshwidget.js" type="text/javascript"></script>
<script type="text/javascript">
FreshWidget.init("", {
"queryString": "&helpdesk_ticket[requester]=<?= urlencode($email) ?>",
"widgetType": "popup", "buttonType": "text",
"buttonText": "Support",
"buttonColor": "white", "buttonBg": "#338700",
"alignment": "4",
"offset": "235px", "formHeight": "500px",
"url": "http://xxxxxx.freshdesk.com"} );
</script>