{"id":1022,"date":"2024-05-25T10:03:40","date_gmt":"2024-05-25T10:03:40","guid":{"rendered":"https:\/\/www.appfinz.com\/blogs\/?p=1022"},"modified":"2025-05-15T05:02:57","modified_gmt":"2025-05-15T05:02:57","slug":"get-the-customer-user_id-in-woocommerce-email-footer-template","status":"publish","type":"post","link":"https:\/\/www.appfinz.com\/blogs\/get-the-customer-user_id-in-woocommerce-email-footer-template\/","title":{"rendered":"Get the customer user_id in Woocommerce email footer template"},"content":{"rendered":"\n<p>You can&#8217;t get the current user in woocommerce email templates, but you can get the customer user ID from the Order.<br><br>To get the customer User ID, you can set and get some data in the $GLOBAL variable:<br>Set the data &#8211; On your active theme<strong> function.php<\/strong> file:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">add_action( 'woocommerce_email_header', 'wc_email_user_id', 10, 2 );\nfunction wc_email_user_id( $email_heading, $email ) {\n    \/\/ Set global variable data: user ID and Order ID\n    $GLOBALS['emails_custom_data'] = array(\n        'user_id' =&gt; get_post_meta( $email-&gt;object-&gt;ID, '_customer_user', true ), \/\/ Set the user ID\n        'order_id' =&gt; $email-&gt;object-&gt;ID, \/\/ Set the Order ID\n    );\n}<\/pre><\/div>\n\n\n\n<p><strong>Get the data<\/strong>&nbsp;&#8211; On your template file just after:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">if ( ! defined( 'ABSPATH' ) ) {\n    exit; \/\/ Exit if accessed directly\n}\n\n## --- Your custom Code start here --- ##\n\n$refNameGlobalsVar = $GLOBALS; \/\/ Get the data\n$custom_data = $refNameGlobalsVar['emails_custom_data']; \/\/ Set the data in a variable\n\n$user_id = $custom_data['user_id']; \/\/ Get the user ID\n$order_id = $custom_data['order_id']; \/\/ Get the order ID (in case of\u2026)\n\n\/\/ Testing output\necho '&lt;p&gt;The user ID is '.$user_id.' |\u00a0From the Order ID: '.$order_id.'&lt;\/p&gt;';\n\n## --- End of custom code --- ##\n\n?&gt;<\/pre><\/div>\n\n\n\n<p class=\"has-background\" style=\"background-color:#eef4fd\">If you\u2019re planning to revamp your online presence, don\u2019t miss exploring our\u00a0<a href=\"https:\/\/www.appfinz.com\/website-designing-company-in-delhi\"><strong>website designing services<\/strong><\/a>\u00a0and custom\u00a0<strong><a href=\"https:\/\/www.appfinz.com\/website-development-company-in-delhi\">website development<\/a><\/strong>\u00a0solutions tailored to your business needs.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can&#8217;t get the current user in woocommerce email templates, but you can get the<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[145],"tags":[],"class_list":["post-1022","post","type-post","status-publish","format-standard","hentry","category-wordpress"],"_links":{"self":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/1022","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/comments?post=1022"}],"version-history":[{"count":2,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/1022\/revisions"}],"predecessor-version":[{"id":1369,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/1022\/revisions\/1369"}],"wp:attachment":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/media?parent=1022"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/categories?post=1022"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/tags?post=1022"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}