Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Add Shipping Class Name Under Items in WooCommerce New Order Emails?

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.

How to Add Shipping Class Name Under Items in WooCommerce New Order Emails? - Tyche Softwares

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.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible.

Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

By using our site, you acknowledge that you have read and understood our Privacy Policy and Terms & Conditions.