简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM