Change name of S2 Member role to Mill Member so appears on Woocommerce invoice

Hi

I have changed the name of s2member_level1 to Mill Member using plugin User Role Editor.

I am using woocommerce, and i have a function which adds a new role column to the orders page:

/***add customer role column to orders***/

add_filter('manage_edit-shop_order_columns', 'add_column_heading', 20, 1);

function add_column_heading($array) {


$res = array_slice($array, 0, 2, true) +
        array("customer_role" => "Customer Role") +
        array_slice($array, 2, count($array) - 1, true);

return $res;
}

add_action('manage_posts_custom_column', 'add_column_data', 20, 2);

function add_column_data($column_key, $order_id) {

// exit early if this is not the column we want
if ('customer_role' != $column_key) {
    return;
}

$customer = new WC_Order( $order_id );
if($customer->user_id != ''){
        $user = new WP_User( $customer->user_id );
         if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
        foreach ( $user->roles as $role )
           echo $role;
    }
}
}

This has successfully added s2member_level1, but it should be Mill Member, as is on the user page, which, by default, has a role column.

Ultimately, I would like the new role name to display on invoices. I am using plugin Woocommerce Pdf Invoices & Packing Slips. On their template in themename/woocommerce/pdf/invoice.php I have added some code:

<?php /* Add Shopper Role to Receipt START */ ?>
<div class=”shopper-role”>
<h3><?php
$cust_user = get_post_meta( $order->id, '_customer_user', true ); //get user for order
$user_info = get_userdata($cust_user); //get user info for user
//echo '' . ucwords(implode(', ', $user_info->roles)) . "\n"; //get the roles for the user & make them 
titlecase with ucwords
$cust_role = implode(', ', $user_info->roles);
if( $cust_role == 's2member_level1' ){
echo '' .ucwords($cust_role)."\n";
}
/* Add Shopper Role to Receipt END */ ?></h3> </div><!– .shopper-role –>

The role is being successfully displayed, but not as Mill Member, which it should be, but the role ID, which is s2member_level1.

I think the role name Mill Member should be displayed on the orders page instead of s2member_level1 so it displays on the invoice.

Perhaps it is the functions code which needs to be updated to display role name? But Im not sure, there’s quite a lot going on, and I’m not an expert!

Can anyone see where I may be going wrong, suggest a code tweak, or a plugin that may help with this?

Cheers

Matt

Hi Matt,

If that message won’t change based on the level, because you’re already checking that he’s level 1, you can use the name directy in the string…

if ($cust_role == 's2member_level1') {
   echo 'Mill Member' . "\n";
}

Does that help? :slight_smile:

Hi

thanks for that, is another way of doing, which i may try, as current code a bit ugly, but is working, for that reason i wont post yet.

But i just coded in:

{$role_name}

Matt