How to add (and change the font of) the short product description to order page and customer's new order e-mail

I'd like to add the short product description to the e-mail that is sent to the customer when a new order is confirmed.

I've added the following via a code snippets plug-in:

add_filter( 'woocommerce_order_item_name', 'add_single_excerpt_to_order_item', 10, 3 );
function add_single_excerpt_to_order_item( $item_name, $item, $is_visible ){
    $product_id = $item-get_product_id(); // Get the product Id
    $excerpt = get_the_excerpt( $product_id ); // Get the short description
    return $item_name . 'brp class="item-description"' . $excerpt ; '/p';
}

It is working correctly by adding the short description but now I would like to change the font type and size to match the rest of the e-mail.

Can you assist, please?

Topic woocommerce-offtopic html-email email templates Wordpress

Category Web


I don't know what the font is for the rest of the email but if you can discern that by examining one of the emails sent you'll want to copy the style rule to this element:

return $item_name . '<br><p class="item-description">' . $excerpt ; '</p>';

As this is an email you'll have to rely on fonts available to the user, so check the email and locate what fonts are being assigned and then add them like this:

return $item_name . '<br><p class="item-description" style="font-family:WHATEVERTHEFONTIS,Arial,Helvetica,sans-serif;font-size:XXpx;font-weight:XXpx;">' . $excerpt ; '</p>';

In earnest though, you'd be better off overriding the email templates using standard WooCommerce (I'm assuming this is for WooCommerce.) template overrides in your theme/child theme.

https://docs.woocommerce.com/document/template-structure/

That will give you full control over the templates and rather than inline styling will allow you to update the actual <style> at the start of the email.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.