{"id":1024,"date":"2024-05-25T10:04:28","date_gmt":"2024-05-25T10:04:28","guid":{"rendered":"https:\/\/www.appfinz.com\/blogs\/?p=1024"},"modified":"2024-05-25T10:04:28","modified_gmt":"2024-05-25T10:04:28","slug":"add-shipping-class-under-items-in-new-order-email-in-woocommerce","status":"publish","type":"post","link":"https:\/\/www.appfinz.com\/blogs\/add-shipping-class-under-items-in-new-order-email-in-woocommerce\/","title":{"rendered":"Add shipping class under items in New Order email in WooCommerce?"},"content":{"rendered":"\n<p>The following will display The product shipping class name in Woocommerce &#8220;New Order&#8221; 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\/\/ Display Items shipping class name in New Order email notification\nadd_filter( 'woocommerce_order_item_name', 'custom_order_item_name', 10, 3 );\nfunction custom_order_item_name( $item_name, $item, $is_visible ) {\n    \/\/ Targeting email notifications only\n    if( is_wc_endpoint_url() ) return $item_name;\n\n    \/\/ Get the WC_Product object (from order item)\n    $product = $item-&gt;get_product();\n\n    if( $shipping_class_id = $product-&gt;get_shipping_class_id() ){\n        \/\/ Getting the email ID global variable\n        $refNameGlobalsVar = $GLOBALS;\n        $email_id = $refNameGlobalsVar['email_id_str'];\n\n        \/\/ Only for New Order email notification\n        if( ! empty($email_id) &amp;&amp; 'new_order' === $email_id ) {\n            $shipping_class_name = get_term( $shipping_class_id, 'product_shipping_class' )-&gt;name;\n            $item_name .= '&lt;br&gt;&lt;p class=&quot;item-shipping_class&quot; style=&quot;margin:12px 0 0;&quot;&gt;\n            &lt;strong&gt;' . __( 'Shipping class', 'woocommerce' ) . ': &lt;\/strong&gt;' . $shipping_class_name . '&lt;\/p&gt;';\n        }\n    }\n\n    return $item_name;\n}<\/pre><\/div>\n\n\n\n<p>Code goes in functions.php file of your active child theme (or active theme). Tested and works.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The following will display The product shipping class name in Woocommerce &#8220;New Order&#8221; Email notification:<\/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-1024","post","type-post","status-publish","format-standard","hentry","category-wordpress"],"_links":{"self":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/1024","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=1024"}],"version-history":[{"count":1,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/1024\/revisions"}],"predecessor-version":[{"id":1025,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/1024\/revisions\/1025"}],"wp:attachment":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/media?parent=1024"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/categories?post=1024"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/tags?post=1024"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}