Share feedback, ideas and get community help

D
F
M
a
g

Get current user_id on wordpress for custom variable (Solved)

any clue how i can achive this? cause when i run as client side it wont get the data on typebot
i
4 comments
Get current user_id on wordpress for custom variable (Solved)
thanks for this great tools! now i can full automate my whole member include payment gateway without woocommerce so if u need this case too here how u can solve it
Create php snippet or inject this code to ur function.php child theme

function add_user_id_to_footer() { if (is_user_logged_in()) { $current_user = wp_get_current_user(); echo '<script>var currentUserId = ' . json_encode($current_user->ID) . ';</script>'; } } add_action('wp_footer', 'add_user_id_to_footer');
then just add your typebot embed script + prefilledvariables

<typebot-standard style="height: 100vh; "></typebot-standard> <script> const typebotInitScript = document.createElement("script"); typebotInitScript.type = "module"; typebotInitScript.innerHTML = import Typebot from 'https://cdn.jsdelivr.net/npm/@typebot.io/[email protected]/dist/web.js'

Typebot.initStandard({
typebot: "YOUR-BOT-ID",
prefilledVariables: {
user_id: currentUserId.toString(),
},
apiHost: "YOUR-TYPEBOT-HOST",
});
; document.body.append(typebotInitScript); </script>
Add a reply
Sign up and join the conversation on Discord
Join
'; }\n}\nadd_action('wp_footer', 'add_user_id_to_footer');","dateCreated":"2024-02-14T04:03:45.232Z","dateModified":"2024-02-14T04:03:45.232Z","author":{"@type":"Person","url":"https://community.typebot.io/members/62253d1b-d887-4c50-a25d-5e6415faaa9b","name":"imoclub","identifier":"62253d1b-d887-4c50-a25d-5e6415faaa9b","image":"https://cdn.discordapp.com/avatars/652171198867963923/97f5ac2f0e0e90d747a4297611c423b6.webp?size=256"},"commentCount":0,"comment":[],"position":3,"upvoteCount":0},"3":{"@type":"Comment","text":"then just add your typebot embed script + prefilledvariables\n","dateCreated":"2024-02-14T04:06:30.699Z","dateModified":"2024-02-14T04:06:30.699Z","author":{"@type":"Person","url":"https://community.typebot.io/members/62253d1b-d887-4c50-a25d-5e6415faaa9b","name":"imoclub","identifier":"62253d1b-d887-4c50-a25d-5e6415faaa9b","image":"https://cdn.discordapp.com/avatars/652171198867963923/97f5ac2f0e0e90d747a4297611c423b6.webp?size=256"},"commentCount":0,"comment":[],"position":4,"upvoteCount":0},"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Get current user_id on wordpress for custom variable (Solved)","datePublished":"2024-02-14T01:26:57.624Z","dateModified":"2024-02-14T01:26:57.624Z","commentCount":4,"text":"any clue how i can achive this? cause when i run as client side it wont get the data on typebot","url":"https://community.typebot.io/questions-and-bug-reports-1f0FwSyXPX30/get-current-userid-on-wordpress-for-custom-variable-solved-WYcZCZpm6sN9","identifier":"WYcZCZpm6sN9","publisher":{"@type":"Organization","name":"Typebot","logo":{"@type":"ImageObject","url":"https://assets.usehall.com/org_01J5WY498Z4HFNZA1D6GQGBV59/079223ba-f2d1-4825-8243-501026f6f74c.png"}},"author":{"@type":"Person","url":"https://community.typebot.io/members/62253d1b-d887-4c50-a25d-5e6415faaa9b","name":"imoclub","identifier":"62253d1b-d887-4c50-a25d-5e6415faaa9b","image":"https://cdn.discordapp.com/avatars/652171198867963923/97f5ac2f0e0e90d747a4297611c423b6.webp?size=256"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0}}]