phpcsswordpresswoocommerceemail-notifications

Change CSS Only for WooCommerce New Order Notification sent to Admins


I want to change the header table design on new order notifications only for my admins. Customer emails should be unaffected. The code I have is below but it does not seem to want to work. Any help would be greatly appreciated.

 add_filter( 'woocommerce_email_styles', 'add_css_to_new_order_email', 9999, 2 );

function add_css_to_new_order_email( $css, $email ) { 
   if ( $email->id == 'new_order' && $email->recipient == 'admin' ) {
      $css .= '
         #header_wrapper { background-color: #000!important; }
         h1 { color: #000!important; }
      ';
   }
   return $css;
}

Solution

  • In your IF statement, $email->recipient == 'admin' will always be false as you need to define the real admin email.

    As New Order email notification is always sent to the admins only (but not to the customer), you don't need $email->recipient == 'admin' in your IF statement.

    Try the following:

    add_filter( 'woocommerce_email_styles', 'add_css_to_new_order_email', 20, 2 );
    function add_css_to_new_order_email( $css, $email ) { 
        if ($email->id === 'new_order') {
            $css .= ' #header_wrapper { background-color: #000 !important; } 
            h1 { color: #000 !important; }';
        } 
        return $css;
    }
    

    Code goes in functions.php file of your child theme (or in a plugin). Tested and works.


    Related: