Share feedback, ideas and get community help

Updated 10 months ago

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
'; }\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},{"@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}],"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}}]