The code snippet provided here help store owners to identify orders that may require special handling or attention as the shipping class name is shown under the product items.
// Setting the email_is as a global variable add_action('woocommerce_email_before_order_table', 'ts_email_id_as_a_global', 1, 4); function ts_email_id_as_a_global($order, $sent_to_admin, $plain_text, $email ){ $GLOBALS['email_id_str'] = $email->id; } // Display Items shipping class name in New Order email notification add_filter( 'woocommerce_order_item_name', 'ts_custom_order_item_name', 10, 3 ); function ts_custom_order_item_name( $item_name, $item, $is_visible ) { // Targeting email notifications only if( is_wc_endpoint_url() ) return $item_name; // Get the WC_Product object (from order item) $product = $item->get_product(); if( $shipping_class_id = $product->get_shipping_class_id() ){ // Getting the email ID global variable $refNameGlobalsVar = $GLOBALS; $email_id = $refNameGlobalsVar['email_id_str']; // Only for New Order email notification if( ! empty($email_id) && 'new_order' === $email_id ) { $shipping_class_name = get_term( $shipping_class_id, 'product_shipping_class' )->name; $item_name .= '<br><p class="item-shipping_class" style="margin:12px 0 0;"> <strong>' . __( 'Shipping class', 'woocommerce' ) . ': </strong>' . $shipping_class_name . '</p>'; } } return $item_name; }
Output
The below output shows that the shipping class name of the particular product is retrieved and shown in WooCommerce ‘New Order’ email notifications.
Similar customization can be done easily using these simple code snippets. Refer to our guide where you can also display the product image in WooCommerce email notifications.