Share feedback, ideas and get community help

Updated 11 months ago

Get current user_id on wordpress for custom variable (Solved)

At a glance
The post asks for a way to get data on Typebot when running it on the client-side. The comments provide a solution, which involves creating a PHP snippet to add the current user's ID to the page footer as a JavaScript variable. This variable can then be used in the Typebot embed script to pre-fill the user ID. The community members also mention that this solution can be used to fully automate a membership site, including the payment gateway, without using WooCommerce.
Useful resources
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}}]