Is it possible to add the vendor name to the listing submit email notification to admin user?

I can’t find this event in the WP dashboard in order to overwrite the functionality.

Also I am thinking of creating a filter with the hook hivepress/v1/emails/listing_submit, but I think I don’t have access to the variable %user_name%, because it doesn’t work when I modify the $email[‘body’].

Thanks and regards,

Hi,

Unfortunately, admin emails cannot be customized there. Therefore, in order to make these changes, you will need a custom implementation.

Thanks Andrii, I have already done by two ways:

  1. With a custom implementation:

I have been checking that the user is defined as a token in the constructor, so it should be accesible like other tokens such as %listing_title% or %listing_url%, but user is defined in this way:

'user'               => hivepress()->request->get_user(),

But defining “user” in this way, it is an array. How is it possible to access the data from the array in the constructor? If it’s not possible, is it a bug?

If it was defined like:

'user'               => hivepress()->request->get_user()->get_username(),

It could be easily called by a filter without customization.

  1. With a filter: So I don’t be able to access the username from the array, I access from a different way. This is the filter:
add_filter(
	'hivepress/v1/emails/listing_submit',
	function( $email ) {
		
		$user_id = get_current_user_id();
		$user = \HivePress\Models\User::query()->get_by_id($user_id);
		$user_name = $user->get_username();
				
		$email['body'] = "VENDOR: ". $user_name ." - " . $email['body'];

		return $email;
	}
);

Could you please clarify if it is any way to access the user from the array in the first option?
Second option is also good?

Thanks and regards,

I finally solved with a better elegant filter:

add_filter(
	'hivepress/v1/emails/listing_report',
	function( $email ) {
		
		$user = $email['tokens']['user'];
		$user_name = $user->get_username();
			
		$email['body'] = "<b>Reported by: ". $user_name . " - </b>" . $email['body'];

		return $email;
	}
);

Thanks and regards!

1 Like