Add vendor name to the message button label

Hey,

Someone else recently asked about changing the ‘Reply to Listing’ text label that’s shown on the listing pages, which I helped resolve. However, it got me thinking of alternatives and I wondered if HivePress/Loco Translate allows us to use a variable label.

So, for example:

Listing A by ChrisB shows a button with “Message ChrisB”

Listing B by @ihor shows a button with “Message Ihor”

And, so on.

(If not, would this be possible with snippets to apply to the relevant profile and listing page buttons?)

Cheers,
Chris :victory_hand:

Hi,

Sorry for the delay,

It’s possible if you override this template part using a child theme hivepress-messages/templates/listing/view/page/message-send-link.php at master · hivepress/hivepress-messages · GitHub You can add the vendor name $listing->get_vendor__name() to the button label there.

Hope this helps

1 Like

Hey,

Sorry to bump this topic again. I’m finally getting around to trying this out, but the button label doesn’t seem to be updating.

I tried copying the message-send-link.php file to both public_html > wp-content > themes > listinghive-child > hivepress-messages > listing > view > page and
public_html > wp-content > themes > listinghive-child > hivepress-messages > templates > listing > view > page but neither attempt seem to be taking priority after making changes.

I’m using AI to try and piece things together and I’ve tried few suggestions:

<?php
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
?>
<button type="button" class="hp-listing__action hp-listing__action--message button button--large button--primary alt" data-component="link" data-url="#<?php if ( is_user_logged_in() ) : ?>message_send_modal_<?php echo esc_attr( $listing->get_id() ); else : ?>user_login_modal<?php endif; ?>"><?php echo esc_html( 'Message ' . $listing->get_vendor__name() ); ?></button>
<?php
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
?>
<button type="button" class="hp-listing__action hp-listing__action--message button button--large button--primary alt" data-component="link" data-url="#<?php if ( is_user_logged_in() ) : ?>message_send_modal_<?php echo esc_attr( $listing->get_id() ); else : ?>user_login_modal<?php endif; ?>">
    <?php 
    $vendor_name = $listing->get_vendor__name();
    echo esc_html( sprintf( 
        /* translators: %s: Vendor name. */
        __( 'Message %s', 'hivepress' ), 
        $vendor_name ? $vendor_name : hivepress()->translator->get_string( 'reply_to_listing' ) 
    ) ); 
    ?>
</button>
<?php
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
?>
<button type="button" class="hp-listing__action hp-listing__action--message button button--large button--primary alt" data-component="link" data-url="#<?php if ( is_user_logged_in() ) : ?>message_send_modal_<?php echo esc_attr( $listing->get_id() ); else : ?>user_login_modal<?php endif; ?>">
    <?php 
    $vendor_name = $listing->get_vendor__name();
    echo esc_html( $vendor_name ? 'Message ' . $vendor_name : hivepress()->translator->get_string( 'reply_to_listing' ) ); 
    ?>
</button>

But, sadly, none of them appear to be working as expected. It would be much appreciated if you’re able to test this on your end/point me in the right direction.

Cheers,
Chris :victory_hand:

Please try using listinghive-child/hivepress/listing/view/page/message-send-link.php path instead (the sub-folder is always “hivepress” regardless of the extension), it should start overriding the default template part then.

Ahhh! okay, thank you for clarifying that. I’ll test this out later!

Just confirming this worked perfectly. Thanks again!

Note to self/others:

If you’d like all of the buttons with vendor/user names, you’ll need to copy over these two files, as well:

templates/vendor/view/page/message-send-link.php
templates/user/view/page/message-send-link.php