php - 将产品简短描述添加到 WooCommerce 电子邮件通知
问题描述
基于将产品描述添加到 WooCommerce 电子邮件通知答案,如何在两个电子邮件通知中添加产品简短描述而不是产品描述(往往更长)?
解决方案
要显示发送给管理员的电子邮件通知的简短描述,请使用以下命令:
// 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>';
}
}
代码位于活动子主题(或活动主题)的 functions.php 文件中。它应该工作。