Home > Software engineering >  How to change the color and bold of the text
How to change the color and bold of the text

Time:01-29

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

CodePudding user response:

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 = '[email protected]';
$subject = 'The subject';
$body = 'The email body content';
$headers = array('Content-Type: text/html; charset=UTF-8');

wp_mail( $to, $subject, $body, $headers );

CodePudding user response:

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 );

CodePudding user response:

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 );
  • Related