• Resolved sorceweb

    (@sorceweb)


    Hi

    Just looking at https://www.ads-software.com/support/topic/display-role-on-invoice-or-receipt/

    I have managed to also get the role displaying on the invoice using mowlman’s code, which is great.

    However, i require some tweaks, and the topic ‘Display Role on Invoice or Receipt’ is closed to new replies.

    So, here is the code again:

    <?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 ‘Shopper Role : ‘ . ucwords(implode(‘, ‘, $user_info->roles)) . “\n”; //get the roles for the user & make them titlecase with ucwords
    
    /* Add Shopper Role to Receipt END */ ?></h3> </div><!– .shopper-role –>

    I would like to only display this when the customer is of a specific role, and, also, the invoice, with code above, is displaying the user role id, not the user role name, which is what i want, e.g. Mill Member.

    Help with this very much appreciated.

Viewing 8 replies - 1 through 8 (of 8 total)
  • mowlman

    (@mowlman)

    Not sure why yours is displaying the role id, mine displays the actual role name such as customer or contractor1.

    For only displaying for a specific role, you should be able to modify your code to check for that specific code, then only echo it when it matches:

    
    $cust_role = implode(', ', $user_info->roles);
    if( $cust_role == 'whateveryourspecificroleis' ){
        echo 'Shopper Role : ' .ucwords($cust_role)."\n";
    }
    
    Thread Starter sorceweb

    (@sorceweb)

    it may be because it’s an s2member role

    ill try out your code, but also see why showing ID not name

    thank you Mowlman, you are very helpful.

    Thread Starter sorceweb

    (@sorceweb)

    your code worked, but still saying s2member_levell

    mowlman

    (@mowlman)

    I think you are going to have to contact the s2member plugin support to see how they recommend pulling in the role? They must be saving it within their own method metadata and not the standard user. Maybe look within wp_usermeta table for s2member maybe it will help?

    Plugin Support kenil802

    (@kenil802)

    Hi @sorceweb,

    We agree with @mowlman. The s2member plugin must be storing the metadata in some other way. You can contact them and ask them how you can fetch the value.

    Regards,
    Kenil Shah

    Thread Starter sorceweb

    (@sorceweb)

    Hi

    $cust_role displays the role id, not the role name, fine if you have a one word id like ‘contractor’, not if you need to display a two word role such as Mill Member, with capitals, so, i coded in $role_name.

    Fairly obvious and easy if you know what you are doing, but took me a bit of looking into, im no expert.

    Matt

    Plugin Support kenil802

    (@kenil802)

    Hi @sorceweb,

    We have fixed the above-mentioned issue. So, can you please try whether it is working fine or not?

    Please let us know how it goes.

    Regards,
    Kenil Shah

    Thread Starter sorceweb

    (@sorceweb)

    you haven’t fixed anything

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Display Role on Invoice or Receipt Part 2’ is closed to new replies.