Listing Title and Listing URL option for email templates

Hi, I’ve seen a number of posts regarding this, but I Imagine its as important for others as it is for me. The customer message received email still doesn’t have the option for listing title and listing url tokens and it pretty much makes the message defunct. I have customers with multiple listing’s who have no idea what listing the message relates to. I have investigated creating Web hooks but it’s not something I’m entirely comfortable with. Sure, as is generally mentioned…hire a developer, but the purpose of me purchasing an out ‘of the box solution’ was to eliminate this requirement.

I also see that it could be such an easy fix just to include the token for this email notification and would avoid not just me, but any other user requiring this option to pay additional money for a developer.

I’m familiar with adding PHP via code snippets. Is there a simple PHP code that could be provided to eliminate this issue until an update is carried out. This suggestion was made a number of years ago now, but it hasn’t happened.

Hi @Gavin,

Welcome back to the community! :honeybee:

Do you have the latest version of HivePress installed, (and any extensions that you’re using)?

There was actually an update a while back that improved the available dynamic placeholders/tokens. When you visit the template for the corresponding email, you should find a fairly large list of these below the box where you compose the email.

Additionally, you may find this topic I created a while ago useful.

I hope this helps!

Edit: I believe the two dynamic tokens you’re looking for are:

  • %listing.title%
  • %listing_url%

You can also combine the URL token with HTML to make it clickable, like so:

<a href="%listing_url%">View Your Listing</a>

Cheers,
Chris :victory_hand:

Hi Chris, and thanks for responding.

I have hivepress and all related plugins up to date.

The token(s) %listing_url% or %listing_title% don’t exist within the options for ‘message received’ when editing Hivepress - emails.

I read the topic you referred to previously as I scoured the community for an answer, but it refers to creating Web hooks which are outside of my confident capabilities. I thought that a platform would address this in a more user friendly basic manner that allowed an average website owner such as myself the simple option of including the token in the email templates.

Am I missing something?

Many thanks,

Gavin

Hey @Gavin,

I understand the issue now. I’ve had a dig around the forum and quizzed the HivePress AI for you, and I’ve eventually come up with a solution. Though, I’ve yet to test it myself.

Snippet to Add Listing Title and URL to Message Received Email:

add_filter(
	'hivepress/v1/emails/message_receive',
	function ( $email_args ) {
		$message = $email_args['tokens']['message'];

		if ( $message ) {
			$listing = $message->get_listing();

			if ( $listing ) {
				$email_args['tokens']['listing_title'] = $listing->get_title();
				$email_args['tokens']['listing_url']   = hivepress()->router->get_url( 'listing_view_page', [ 'listing_id' => $listing->get_id() ] );
			}
		}

		return $email_args;
	},
	1000
);

What This Does:

  1. Targets the email: Hooks into message_receive — the email sent when someone receives a message.
  2. Extracts message data: Gets the message object from the email tokens.
  3. Gets listing information: Retrieves the listing associated with that message.
  4. Adds tokens: Creates two new tokens you can use in your email template:
  • %listing_title% — displays the listing title
  • %listing_url% — displays the full URL to the listing

How to Use:

Add the above PHP snippet using a plugin like Code Snippets.

Once this snippet is active, you can add these tokens to your Message Received email template. E.g.

You received a message about: %listing_title%
View listing: %listing_url%

This will display the actual listing title and a clickable link to the listing in the email.

Again, I’ve yet to test this, and the snippet provided was generated with AI, so it may need tweaking slightly. Nevertheless, this should point you in the right direction!

Cheers,
Chris :victory_hand:

Thanks for the effort Chris but unfortunately this doesn’t work. Added via code snippets, deleted the original message received email and created another to see if it would refresh. But, nothing changed :frowning:

Hi @Gavin,

Just to clarify, the above snippet wouldn’t show the new tokens in the Display box, however, they may still work as intended when the emails are sent. Apologies if you’ve already tried this! .. I kinda “vibe code” everything, but when the staff get round to replying they may be able to help achieve this by correcting the snippet if need be.

Cheers,
Chris :victory_hand:

1 Like

Thanks Chris, yes I inserted the tokens in the email template as I noticed they didn’t show as options.

Once again, thanks for your time.

Thanks for your feedback, we’ll try to improve this by adding 2 separate email templates, because currently there’s no listing token by default since messages are not always sent via the listing page (so there may be no assigned listing). There’s a sample code snippet that you can use to add listing tokens and replace the email subject and/or text entirely (keeping the same text with listing tokens may leave placeholders without values for direct messages):

add_filter(
	'hivepress/v1/emails/message_send',
	function( $email ) {
		if ( ! isset( $email['tokens']['message'] ) ) {
			return $email;
		}

		$message = $email['tokens']['message'];

		if ( ! $message->get_listing__id() ) {
			return $email;
		}

		$listing = $message->get_listing();

		if ( ! $listing ) {
			return $email;
		}

		$email['tokens']['listing_title'] = $listing->get_title();
		$email['tokens']['listing_url']   = get_permalink( $listing->get_id() );

		$email['body'] = 'custom text for messages linked to listings, with tokens like %listing_title% and %listing_url%';

		return $email;
	}
);

Hope this helps

1 Like

Thanks Ihor, I’ll give this a try

1 Like

Thanks Ihor, this worked perfectly. The only thing I would say to anyone else requiring this is if you already have an email template saved for message received, delete it and use the snippet section $email[‘body’] for inserting the code from your template.