{"id":1026,"date":"2024-05-25T10:05:33","date_gmt":"2024-05-25T10:05:33","guid":{"rendered":"https:\/\/www.appfinz.com\/blogs\/?p=1026"},"modified":"2024-05-25T10:05:43","modified_gmt":"2024-05-25T10:05:43","slug":"add-a-custom-text-for-a-particular-product-on-specific-email-notification-in-woocommerce","status":"publish","type":"post","link":"https:\/\/www.appfinz.com\/blogs\/add-a-custom-text-for-a-particular-product-on-specific-email-notification-in-woocommerce\/","title":{"rendered":"Add a custom text for a particular product on specific email notification in Woocommerce"},"content":{"rendered":"\n<p>The following will display a custom text under a order item name for a specific product in Customer Completed email notification:<\/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 email_is as a global variable\nadd_action('woocommerce_email_before_order_table', 'the_email_id_as_a_global', 1, 4);\nfunction the_email_id_as_a_global($order, $sent_to_admin, $plain_text, $email ){\n    $GLOBALS['email_id_str'] = $email-&gt;id;\n}\n\n\/\/ Displaying product description in new email notifications\nadd_action( 'woocommerce_order_item_meta_end', 'product_description_in_new_email_notification', 10, 3 );\nfunction product_description_in_new_email_notification( $item_id, $item, $order = null ){\n    \/\/ HERE define your targetted product ID\n    $targeted_id = 37;\n\n    \/\/ HERE define the text information to be displayed for the targeted product id\n    $text_information = __(&quot;There is an offer in this particular item&quot;, &quot;woocommerce&quot;);\n\n    \/\/ Getting the email ID global variable\n    $refNameGlobalsVar = $GLOBALS;\n    $email_id = $refNameGlobalsVar['email_id_str'];\n\n    \/\/ If empty email ID we exit\n    if(empty($email_id)) return;\n\n    \/\/ Only for &quot;New Order email notification&quot; for your targeted product ID\n    if ( 'customer_completed_order' == $email_id &amp;&amp;\n        in_array( $targeted_id, array( $item-&gt;get_product_id(), $item-&gt;get_variation_id() ) ) ) {\n\n        \/\/ Display the text\n        echo '&lt;div class=&quot;product-text&quot; style=&quot;margin-top:10px&quot;&gt;&lt;p&gt;' . $text_information . '&lt;\/p&gt;&lt;\/div&gt;';\n    }\n}<\/pre><\/div>\n\n\n\n<p>Code goes in function.php file of your active child theme (active theme). Tested and works.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The following will display a custom text under a order item name for a specific<\/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-1026","post","type-post","status-publish","format-standard","hentry","category-wordpress"],"_links":{"self":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/1026","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=1026"}],"version-history":[{"count":1,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/1026\/revisions"}],"predecessor-version":[{"id":1027,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/1026\/revisions\/1027"}],"wp:attachment":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/media?parent=1026"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/categories?post=1026"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/tags?post=1026"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}