0

How to change the color and bold of the text in this message sent to an email address?

'The coupon code "%s" has been applied by a customer'

Link to original content

// For all Woocommerce versions (since 3.0)
add_action( 'woocommerce_checkout_update_order_meta', 'custom_email_for_orders_with_applied_coupon' );
function custom_email_for_orders_with_applied_coupon( $order_id ){
    $order = wc_get_order( $order_id );

    $used_coupons = $order->get_used_coupons();

    if( ! empty($used_coupons) ){
        foreach ( $used_coupons as $coupon_code ) {
            $coupon    = new WC_Coupon( $coupon_code ); // WC_Coupon Object
            $recipient = $coupon->get_meta('email_recipient'); // get recipient

            if( ! empty($recipient) ) {
                $subject = sprintf( __('Coupon "%s" has been applied'), $coupon_code );
                $content = sprintf( __('The coupon code "%s" has been applied by a customer'), $coupon_code );
                wp_mail( $recipient, $subject, $content ); // Send email
            }
        }
    }
}

I'm trying to get a css or other styling effect for an email reply

enter image description here

DCR
  • 14,737
  • 12
  • 52
  • 115
Maya
  • 1
  • 1

4 Answers4

0

Did you try HTML? You can add inline css like this: <span style="color:red">word</span>

In case HTML body is not the default of wp_mail which Is the case, you should add the following header:

$to = 'sendto@example.com';
$subject = 'The subject';
$body = 'The email body content';
$headers = array('Content-Type: text/html; charset=UTF-8');

wp_mail( $to, $subject, $body, $headers );
IT goldman
  • 14,885
  • 2
  • 14
  • 28
  • I don't understand what the whole line of text should look like?, thank you... if( ! empty($recipient) ) { $subject = sprintf( __('Coupon "%s" has been applied'), $coupon_code ); $content = sprintf( __('The coupon code "%s" has been applied by a customer'), $coupon_code ); wp_mail( $recipient, $subject, $content ); // Send email } – Maya Jan 30 '23 at 12:11
0

change this line:

 $content = sprintf( __('The coupon code "%s" has been applied by a customer'), $coupon_code );

to:

 $content = sprintf( __('<span style="color:green;">The</span> coupon code <span style="color:green;font-weight:bold;">"%s"</span> has been applied by a customer'), $coupon_code );
DCR
  • 14,737
  • 12
  • 52
  • 115
  • thank you, but unfortunately it doesn't work. email send body, no text color – Maya Jan 28 '23 at 20:25
  • look please: The coupon code "sweb" has been applied by a customer – Maya Jan 28 '23 at 20:26
  • I didn't realize you were using wordpress. Some people swear by sites like wordpress but I have always found them to incur too much overhead and make simple things really complicated – DCR Jan 28 '23 at 20:57
  • Do you know any other solution, can you help me, I will be grateful and thank you... – Maya Jan 29 '23 at 09:14
  • you would probably get a faster answer on the wordpress community forum https://wordpress.com/forums/ – DCR Jan 29 '23 at 15:40
0

Change this:

`$subject = sprintf( __('Coupon "%s" has been applied'), $coupon_code )`;

To this:

$content = sprintf( __('<strong style="color: red;">The coupon code "%s"</strong> has been applied by a customer'), $coupon_code );
0

Below is the solution to my problem.

add_filter('wp_mail_content_type',create_function('', 'return "text/html"; '));
Sven Eberth
  • 3,057
  • 12
  • 24
  • 29
Maya
  • 1
  • 1