{"id":1018,"date":"2024-05-25T09:59:21","date_gmt":"2024-05-25T09:59:21","guid":{"rendered":"https:\/\/www.appfinz.com\/blogs\/?p=1018"},"modified":"2024-05-25T09:59:21","modified_gmt":"2024-05-25T09:59:21","slug":"customize-order-item-meta-only-for-woocommerce-admin-email-notifications","status":"publish","type":"post","link":"https:\/\/www.appfinz.com\/blogs\/customize-order-item-meta-only-for-woocommerce-admin-email-notifications\/","title":{"rendered":"Customize order item meta only for WooCommerce admin email notifications"},"content":{"rendered":"\n<p>This is the perfect answer for your question:<\/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;}\">\/\/ Setting the &quot;sent_to_admin&quot; as a global variable\nadd_action('woocommerce_email_before_order_table', 'email_order_id_as_a_global', 1, 4);\nfunction email_order_id_as_a_global($order, $sent_to_admin, $plain_text, $email){\n    $GLOBALS['email_data'] = array(\n        'sent_to_admin' =&gt; $sent_to_admin, \/\/ &lt;== HERE we set &quot;$sent_to_admin&quot; value\n        'email_id' =&gt; $email-&gt;id, \/\/ The email ID (to target specific email notification)\n    );\n}\n\n\/\/ Conditionally customizing footer email text\nadd_action( 'woocommerce_order_item_meta_end', 'custom_email_order_item_meta_end', 10, 3 );\nfunction custom_email_order_item_meta_end( $item_id, $item, $order ){\n\n    \/\/ Getting the custom 'email_data' global variable\n    $refNameGlobalsVar = $GLOBALS;\n    $email_data = $refNameGlobalsVar['email_data'];\n\n    \/\/ Only for admin email notifications\n    if( ! ( is_array( $email_data ) &amp;&amp; $email_data['sent_to_admin'] ) ) return;\n\n    ## -------------------------- Your Code below -------------------------- ##\n\n    $taxonomy = 'my_custom_taxonomy'; \/\/ &lt;= Your custom taxonomy\n\n    echo '&lt;br\/&gt;&lt;div style=&quot;margin-top: 20px;&quot;&gt;';\n    foreach( get_the_terms( $item-&gt;get_product_id(), $taxonomy ) as $term )\n        echo 'Location:  &lt;b&gt;' . $term-&gt;name . '&lt;\/b&gt;&lt;br\/&gt;';\n    echo '&lt;\/div&gt;';\n}<\/pre><\/div>\n\n\n\n<p><em>Code goes in function.php file of the active child theme (or active theme).<\/em><\/p>\n\n\n\n<p>Tested and works.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is the perfect answer for your question: Code goes in function.php file of 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-1018","post","type-post","status-publish","format-standard","hentry","category-wordpress"],"_links":{"self":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/1018","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=1018"}],"version-history":[{"count":1,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/1018\/revisions"}],"predecessor-version":[{"id":1019,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/1018\/revisions\/1019"}],"wp:attachment":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/media?parent=1018"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/categories?post=1018"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/tags?post=1018"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}