Displaying Vendor name (or custom attribute) on Messages instead of username

Hi there,

Is there a way to display Vendor name and/or a custom attribute for Messages (and Offers too if possible) instead of the Username?

I’m basically looking for a way to replace it everywhere (Messages, Offers, Thread, Email) but would take just in Message views for now.

Cheers,
Jeff

Hi,

Please navigate to HivePress > Settings > Users. If you set the Display Name option to, for example, Full Name, the vendor profile will also display the full name, since vendor names are linked to user names. Please note that this will only work after you change this setting and re-save the profile form for existing users, or for any newly created vendors.

As for the attributes, please refer to this guide on How to customize the vendor names - HivePress Help Center

Hope this helps

We already have it set to Full Name but when a Vendor sends a messages or an offer it displays the First / Last name of the User rather than the Vendor they are associated with. We want to display the Vendor by itself (or both Vendor name and User name if required).

Please note that messages are sent on behalf of users, and the shown name is not the username but the display name, which is configured in HivePress > Settings > Users as mentioned above. If you’re familiar with code or have a developer, you can try customizing the template part that controls how the name appears in messages.

Hope this helps

Yes, I understand that. I’m specifically looking to ALSO display the Vendor Name. I’ve tried editing both the message/thread/message-sender.php and messages/view/message-sender.php files (in both my theme and directly in the plugin. Nothing seems to work.

I was able to adjust the view for Offers to show both the Vendor name and Username but it’s slightly different right? i.e. Offers come from Vendors while messages come from Users.

There has to be a way to pull the name of the Vendor connected to that user though…

Here’s where I’ve gotten to - is there anything glaring I’m missing here:

<?php
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

$display = get_option( 'hp_user_enable_display' );

// Get the sender user ID
$sender_user_id = $message->get_author_id(); // or get_sender_id() depending on HivePress version

// Find the vendor associated with this user
$vendor_name = '';
$vendor_id   = hivepress()->vendors->get_vendor_id_by_user( $sender_user_id );

if ( $vendor_id ) {
    $vendor = hivepress()->vendors->get( $vendor_id );
    if ( $vendor ) {
        $vendor_name = $vendor->get_name() ?: ( $vendor->get_user() ? $vendor->get_user()->display_name : '' );
    }
}

// Always show the WordPress user name
$user_name = $message->get_sender__display_name();

// Build combined display string
$display_name = $vendor_name ? $vendor_name . ' (' . $user_name . ')' : $user_name;
?>

<div class="hp-message__sender">
    <?php if ( $display ) : ?>
        <a href="<?php echo esc_url( hivepress()->router->get_url( 'user_view_page', [ 'username' => $message->get_sender__username() ] ) ); ?>">
    <?php endif; ?>

    <?php echo esc_html( $display_name ); ?>

    <?php if ( $display ) : ?>
       ..</a>
    <?php endif; ?>
</div>

Unfortunately we can’t help with customizations in detail, but we can provide general guidance. When overriding template parts, please make sure that the copied file path is correct, for example for the message sender link:

child-theme-folder/hivepress/message/thread/message-sender.php
child-theme-folder/hivepress/message/view/message-sender.php

You can test if files are overridden by adding random text to the copied files, it should appear instead of the sender names on the messages and single conversation pages. You can get the vendor object by user ID this way:

$vendor = \HivePress\Models\Vendor::query()->filter(
	[
		'status' => [ 'auto-draft', 'draft', 'publish' ],
		'user'   => $message->get_sender__id(),
	]
)->get_first();

Then check if the vendor is not empty and if not you can get name this way $vendor->get_name()

Hope this helps

Thanks @ihor. I’ve been able to get it mainly working by replacing message-sender.php with

defined('ABSPATH') || exit;

// --- STEP 1: Identify the two real participants ---

$other_party_user = $message->get_sender();
$current_user_obj = $message->get_recipient();

// --- STEP 2: Get formatted vendor names for both ---

$their_label = $other_party_user ? $other_party_user->get_display_name() : __( 'Unknown', 'hivepress' );
if ( $other_party_user ) {
    $vendor_posts = get_posts( [ 'post_type' => 'hp_vendor', 'author' => $other_party_user->get_id(), 'numberposts' => 1, 'fields' => 'ids' ] );
    if ( ! empty( $vendor_posts ) ) {
        $their_label = sprintf( '%s (%s)', get_the_title( $vendor_posts[0] ), $other_party_user->get_display_name() );
    }
}

$my_label = $current_user_obj ? $current_user_obj->get_display_name() : __( 'Unknown', 'hivepress' );
if ( $current_user_obj ) {
    $vendor_posts = get_posts( [ 'post_type' => 'hp_vendor', 'author' => $current_user_obj->get_id(), 'numberposts' => 1, 'fields' => 'ids' ] );
    if ( ! empty( $vendor_posts ) ) {
        $my_label = sprintf( '%s (%s)', get_the_title( $vendor_posts[0] ), $current_user_obj->get_display_name() );
    }
}

// --- STEP 3: Apply display rules ---

$display_html = esc_html( $their_label ) . '<br><small style="opacity: 0.7;">To: ' . esc_html( $my_label ) . '</small>';

if ( get_current_user_id() === $message->get_recipient__id() ) {
     $display_html = '<small style="opacity: 0.7;">To: </small>' . esc_html( $their_label );
}

?>
<td class="hp_message__sender">
    <a href="<?php echo esc_url( $message_url ); ?>" class="hp-link">
        <i class="hp-icon fas fa-envelope<?php if ( $message->is_read() ) : ?>-open<?php endif; ?>"></i>
        <span><?php echo $display_html; ?></span>
    </a>
</td>

It’s not super clean, and there are some odd items around the title on Message drill-through but it does what we need for now.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.