• Resolved creoadmin

    (@creoadmin)


    Can you tell me how to add the user’s role to the packing slip? I need to differentiate between my customers and my wholesale customers.

    Thanks!

Viewing 5 replies - 16 through 20 (of 20 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    That’s even more confusing – this doesn’t even include my previous snippets which should print the user roles so I’m not sure how these come up blank now. Weird.

    By the way if you use the “code” button here when posting, (making sure the code starts one line after the backtick) the formatting should be preserved better.

    Thread Starter creoadmin

    (@creoadmin)

    Yikes! Sorry to be confusing. Here is the code copied from my functions file:

    add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_print_user_role', 10, 2 );
    function wpo_wcpdf_print_user_role ($template_type, $order) {
    	if ($template_type == 'packing-slip') {
    	$user = $order->get_user();
    		if ( $user && in_array( 'wholesale_customer', (array) $user->roles ) ) {
    			?>
    			<tr class="user-role">
    				<th>User role:</th>
    				<td>Wholesale customer</td>
    			</tr>
    			<?php
    			} else {
    			?>
    			<tr class="user-role">
    				<th>User role:</th>
    				<td><<?php echo $user ? implode(', ', (array) $user->roles ) : 'not a user'; ?>
    </td>
    			</tr>
    			<?php
    		}
    	}
    }
    Plugin Contributor Ewout

    (@pomegranate)

    That explains… It’s always the little things – there’s a < too much in your code beofre the <?php tag (my fault…).

    This should work:

    
    add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_print_user_role', 10, 2 );
    function wpo_wcpdf_print_user_role ($template_type, $order) {
    	if ($template_type == 'packing-slip') {
    	$user = $order->get_user();
    		if ( $user && in_array( 'wholesale_customer', (array) $user->roles ) ) {
    			?>
    			<tr class="user-role">
    				<th>User role:</th>
    				<td>Wholesale customer</td>
    			</tr>
    			<?php
    			} else {
    			?>
    			<tr class="user-role">
    				<th>User role:</th>
    				<td><?php echo $user ? implode(', ', (array) $user->roles ) : 'not a user'; ?>
    </td>
    			</tr>
    			<?php
    		}
    	}
    }
    
    Thread Starter creoadmin

    (@creoadmin)

    WORKS PERFECT! THANK YOU!!!!

    Plugin Contributor Ewout

    (@pomegranate)

    Very glad to hear that… What a ride! ??

Viewing 5 replies - 16 through 20 (of 20 total)
  • The topic ‘User Role’ is closed to new replies.