user3127909
user3127909

Reputation: 1

How to add WordPress User Role to Woocommerce New Admin Order Email Subject

The Woocommerce website I am building has user roles for retail customers and wholesale customers. I would like to add the User Role as part of the New Order Admin Email Subject Line so that the customer service department will be able to determine which type of order it is. Right now the subject is "[Company Name] New customer order (22315) - August 20, 2018".

I would like it to be "[Company Name] New customer order (22315) - August 20, 2018" where is the user role that get's pulled from WordPress.

Upvotes: 0

Views: 637

Answers (1)

kashalo
kashalo

Reputation: 3562

here you go :

add_filter('woocommerce_email_subject_new_order', 'change_admin_email_subject', 1, 2);
function change_admin_email_subject($subject, $order)
{
    $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    $user_id = $order->get_user_id();
    $user = get_userdata($user_id);
    $user_roles = $user->roles;

    if (in_array('administrator', $user_roles, true)) { //Here you can defind which role do want of course

        $role = 'administrator';
    } else {
        $role = 'Customer';
    }

    $subject = sprintf('[%s] New Customer Order (%s)  role %s %s', $blogname, $order->id, $role, wc_format_datetime($order->get_date_created()));
    return $subject;

}

put this code in your functions.php

This code is test and working.

Upvotes: 1

Related Questions