phpwordpresswoocommerceordersemail-notifications

Add product short description to WooCommerce email notifications


Based on Add the product description to WooCommerce email notifications answer, how to add product short description instead of product description (which tend to be longer) to both email notifications?


Solution

  • To display short description on email notifications sent to admin, use the following:

    // Displaying short product description in email notifications sent to admin
    add_action( 'woocommerce_order_item_meta_end', 'product_description_in_new_email_notification', 10, 4 );
    function product_description_in_new_email_notification( $item_id, $item, $order = null, $plain_text = false ){
        // Only on email notifications
        if( is_wc_endpoint_url() ) return;
    
        $product_obj = wc_get_product( $item->get_product_id() );
        $short_descr = $product_obj->get_short_description();
        
        if( ! empty($short_descr) ) {
            // Display the product description
            echo '<div class="product-description"><p>' . $short_descr . '</p></div>';
        }
    }
    

    Code goes in functions.php file of the active child theme (or active theme). It should work.