Custom tokens not working in some emails

Hello HivePress team,

I’ trying to create a custom booking setup using HivePress Rental Hive + WooCommerce, and I’m trying to make the email system minimal, automatic, and informative. I’ve already read the documentation and used successful examples from your community (including from user lolofora), but I’m still stuck on several issues.
here my last chat that acttuallay helped:

How to add more booking and vendor details to the Booking Confirmed email? - General / Bookings - HivePress Community

:wrench: Current setup:

  • I use 3 email templates:

    • booking_confirm_user (for the guest)
    • booking_confirm_vendor (for the host)
    • booking_accepted (after host approval)
  • I’ve disabled the HivePress Messenger (no contact before approval).

  • WooCommerce via Stripe.


:white_check_mark: Working tokens (confirmed):

  • %booking.start_date%, %booking.end_date%
  • %booking.total%
  • %booking.adults%, %booking.children%
  • %vendor_user.display_name%
  • %vendor_user.email%
  • %user.display_name%, %user.email%

:cross_mark: Not working or inconsistent tokens:

  • %vendor.bank_number% → works in booking_confirm_vendor, but does not work in booking_confirm_user or after booking_accepted
  • %booking.nights% → I need this token, but it doesn’t exist by default.
  • A token for the remaining amount guest has to pay host (total – commission) is missing – I tried calculating it manually in a snippet but it’s unstable.
  • A token for direct pay amount - what is left to pay and hos

:nut_and_bolt: Snippets I currently use:

php

KopiérRediger

add_filter(
  'hivepress/v1/emails/booking_confirm_user',
  function( $email, $booking ) {
    $vendor = $booking->get_vendor();
    $vendor_user = $vendor->get_user();

    $email['tokens']['vendor_user.display_name'] = $vendor_user->get_display_name();
    $email['tokens']['vendor_user.email'] = $vendor_user->get_email();
    $email['tokens']['vendor.bank_number'] = $vendor->get_attribute('bank_number');

    $email['tokens']['booking.total'] = $booking->get_amount();
    $email['tokens']['booking.adults'] = $booking->get_adults();
    $email['tokens']['booking.children'] = $booking->get_children();
    $email['tokens']['user.display_name'] = $booking->get_user()->get_display_name();
    $email['tokens']['user.email'] = $booking->get_user()->get_email();

    return $email;
  },
  10,
  2
);

I have a similar snippet for booking_confirm_vendor.


:magnifying_glass_tilted_left: What I’m asking for:

  1. A full list of HivePress emails (to guest and host) in chronological order — I need to know which ones are triggered when, and which support custom tokens.

  2. How to reliably add a %booking.nights% token.

  3. How to calculate and display a token like %booking.remaining_to_host% = total – commission (so guest sees what to pay host).

  4. How to message amount for “direct pay” to host ( besides fees that are paid), How to get a token to write in a customezed e-mail that amount is xxx to be payen on f.e.s (this bank account = vendor token)

  5. Why %vendor.bank_number% works in some emails but not in others — how to fix this.

I have tried this snippet:

add_filter(
  'hivepress/v1/emails/booking_confirm_user',
  function ( $email, $booking ) {

    $listing = $booking->get_listing();
    $vendor = $listing->get_vendor();
    $vendor_user = $vendor->get_user();
    $user = $booking->get_user();

    // Beregn antal nætter
    $start_date = strtotime( $booking->get_date( 'start' ) );
    $end_date = strtotime( $booking->get_date( 'end' ) );
    $nights = round( ( $end_date - $start_date ) / DAY_IN_SECONDS );

    // Få totalbeløb fra booking
    $total_amount = $booking->get_amount();

    // Tilføj tokens
    $email['tokens']['booking.nights'] = $nights;
    $email['tokens']['booking.total_amount'] = hivepress()->helper->format_amount( $total_amount );

    return $email;
  },
  10,
  2
);

and this snippet

add_filter(
  'hivepress/v1/emails/order_received',
  function ( $email_args ) {
    $booking = $email_args['tokens']['booking'];
    
    if ( $booking ) {
      $listing = $booking->get_listing();
      $vendor = $listing->get_vendor();
      $vendor_user = $vendor->get_user();
      $user = $booking->get_user();

      // Beregn nætter
      $check_in = strtotime( $booking->get_start_date() );
      $check_out = strtotime( $booking->get_end_date() );
      $nights = round( ( $check_out - $check_in ) / ( 60 * 60 * 24 ) );

      // Tokens
      $email_args['tokens']['vendor'] = $vendor;
      $email_args['tokens']['vendor_user'] = $vendor_user;
      $email_args['tokens']['user'] = $user;
      $email_args['tokens']['booking'] = $booking;

      // Beregninger
      $email_args['tokens']['booking_nights'] = $nights;
      $email_args['tokens']['booking_total'] = $booking->get_amount();
      $email_args['tokens']['booking_service_fee'] = $booking->get_fee_amount();
      $email_args['tokens']['booking_direct_payment'] = $booking->get_amount();

      // Custom attributter
      $email_args['tokens']['vendor_phone'] = $vendor->get_attribute( 'phone' );
      $email_args['tokens']['vendor_bank_number'] = $vendor->get_attribute( 'bank_number' );
    }

    return $email_args;
  },
  1000
);

I’ve tried to handle this myself for several weeks and tested everything inside the code reference and community forum. I really need a stable solution now before I go live.

Summary of mi questions:

1. A full list of HivePress emails (to both guest and host), in chronological order.
→ I need to know exactly which emails are triggered when, and which of them support custom object-based tokens like %vendor_user.email%, %booking.adults%, etc.


2. How to reliably add a %booking.nights% token.
→ I want to show guests the number of nights they booked, as a separate field (not just total amount divided by price). Right now, I can’t extract this info cleanly in emails.


3. How to calculate and display a custom token like %booking.remaining_to_host%.
→ It should calculate: booking total – service fee, so the guest knows how much to pay the host directly.


4. How to display amount + bank info for Direct Pay
→ I need a token that allows writing something like:
“Please pay €110 directly to this bank account: %vendor.bank_number% before your arrival.”


5. Why %vendor.bank_number% works in some emails but not others.
→ In booking_confirm_vendor and booking_confirm_user, it works fine (we used custom snippets with $vendor->get_attribute() logic).
But it doesn’t display in other emails like order_received or booking_requested — why not? How can I make it consistent?


We have already used snippets that define $vendor, $vendor_user, $booking, $user and made those tokens work in some emails. But I want to stabilize the system, make sure it works in the right emails, and avoid trial-and-error.

Can you help answer these questions and provide a clear recommendation?

Thank you :folded_hands:

Thank you so much in advance!

Ewjgrass

Hi,

Thanks for your feedback.

Unfortunately, we can’t advise on code customizations in detail – this is outside our support scope. While we can provide general dev guidance if needed, unfortunately we can’t debug custom code or provide custom code on request. You can check the details here Support Policy | HivePress

We plan to add more tokens to the booking emails. If it’s urgent, please use this code snippet to add vendor (and linked user) tokens to the booking confirmation email sent to the customer. If you need the same tokens for other emails, you can use the same snippet and change the “booking_confirm_user” email name.

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

		if ( $booking ) {
			$listing = $booking->get_listing();
			$vendor  = $listing->get_vendor();
			$user    = $vendor->get_user();

			$email_args['tokens']['vendor']      = $vendor;
			$email_args['tokens']['vendor_user'] = $user;
		}

		return $email_args;
	},
	1000
);

You can check the available booking emails here Awesome Screenshot Please note that if you use this snippet, you can access any vendor attribute via a dot, so you don’t have to add new tokens like:

$email['tokens']['vendor.fieldnamehere'] = $vendor->get_fieldnamehere();

It’s the same with the booking, the “booking” token is an object so you can access any of its fields via a dot. Unfortunately developing tokens with custom logic (like the number of nights) requires further customizations, but you can try using workarounds like showing the booking dates via “%booking.dates%”. Also, customers can check the full booking details via the link in the email.

Hope this helps

Hej Ihor,

Thanks a lot!

However when I try to set up my email system on a RentalHive-based site and I’ve tested all booking-related emails with both standard and custom object-based tokens.

In default emails — like “Booking Confirmed (User)” and “Booking Confirmed (Host)” — everything works as expected using your recommended snippet:

:red_exclamation_mark: What’s not working:

In the email triggered by booking_requested, the system does not recognize who is the host and who is the guest.

  • %vendor_user.display_name% is not rendered
  • %user.display_name% shows the host’s name instead of the guest (!)
  • %vendor.bank_number%, %vendor_user.email%, %user.email% are all missing or incorrect
  • Only %listing.*% and %booking.*% tokens work

:test_tube: What I’ve done:

I already added the recommended object-based snippet:

code snippet:

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

  if ( $booking ) {
    $listing = $booking->get_listing();
    $vendor = $listing->get_vendor();
    $vendor_user = $vendor->get_user();
    $guest_user = $booking->get_user();

    $email_args['tokens']['vendor'] = $vendor;
    $email_args['tokens']['vendor_user'] = $vendor_user;
    $email_args['tokens']['user'] = $guest_user;
    $email_args['tokens']['booking'] = $booking;
  }

  return $email_args;
}, 1000 );

I also tried manually adding specific tokens like this:

$email_args[‘tokens’][‘vendor_user.email’] = $vendor_user->get_email();
$email_args[‘tokens’][‘user_display_name’] = $user->get_display_name();
$email_args[‘tokens’][‘booking_nights’] = $nights;

But the result is always the same: the email **shows the host’s name and email as if they booked their own listing. and isted of their own name under teh token `%vendor_user.display_name%, shows the token iteself! **

:light_bulb: My suspicion:

The booking_requested email behaves differently than other emails.
For example, emails like booking_confirm_vendor or booking_confirm_user work perfectly with the same structure — they correctly recognize who is the host and who is the guest.

But booking_requested seems to confuse the user roles. It feels like the recipient logic is inverted — the host receives the email, but tokens return their own data as if they were the guest.


:red_question_mark:My questions:

  1. Is there a known issue with booking_requested and user/vendor role resolution?
  2. Is there a reliable way to display:
  • the host’s name, email, and bank info?
  • the guest’s name and email?
  1. How can code snippet so it will be displayed in final emails: tokens like:

%booking.total%
%booking.service_fee%
%booking.direct_payment%** %booking.remaining_to_host% (e.g. total amount minus service fee)?

Best regards!

Hi,

Please note that there is an issue in the hook name. You need to specify booking_request instead of booking_requested, and everything should work correctly.

As for hooks, please note that they are used as email names, only without “class-” and “underscores”. You can view the names themselves here.

I hope it helps

Hej Andrii og Ihor,

Thank you so much for your support! It helped!

Hovewer I’m try to customize the email templates (especially for emails such as the Booking Request email, and confirmation e-mails to users/customers), and I would like to clearly show the following payment breakdown to the guest:

  • The *full amount for the booking (what the stay costs in total)
  • The *service fee (the platform fee that the guest already paid)
  • The *direct payment (“Direct Pay”) — the remaining amount that must be transferred directly to the host’s bank account (e.g. via IBAN shown below this)

This is very important for me, because I do not want to rely on WooCommerce emails — they are too limited and not editable. My goal is to show this payment breakdown inside the HivePress email right after the guest completes checkout.

I tried registering tokens like:
%booking.amount%, %booking.service_fee% and %booking.direct_payment%

using the snippet below, but these values are either not showing up or are blank when the email is sent:

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

	if ( $booking ) {
		$email_args['tokens']['booking.amount'] = $booking->get_amount();
		$email_args['tokens']['booking.service_fee'] = $booking->get_fee_amount();
		$email_args['tokens']['booking.direct_payment'] = $booking->get_amount() - $booking->get_fee_amount();
	}

	return $email_args;
}, 1000, 1 );

Can you please confirm the correct way to display these amounts as tokens in the email?
Or let me know if this must be done differently (e.g. using booking meta, order data or a different object)?

Best Regars

Sorry for the delay. If you have the booking object, it’s possible to get the linked order this way:

$order = hivepress()->helper->get_first_array_value(
	wc_get_orders(
		[
			'limit'      => 1,
			'meta_key'   => 'hp_booking',
			'meta_value' => $booking->get_id(),
		]
	)
);

Then it’s possible to get the order total, calculate the percentages, etc $order->get_total()

Please note that the order is not available for the booking request so it will not work for the Booking Requested email, but it should be ok for the Booking Confirmed one.

Hi HivePress team,

I’ve tested everything again, but it seems that almost all email events are targeted at the host, not the user. For example, emails like Order Received or Order Delivered only send to the host — and only after the order is created.

But there’s no real email event for the user after the host accepts and confirms the booking.

I want to send a customized email to the user (guest) after host confirmation – e.g. with:
• Order number
• Remaining amount to pay to host
• Vendor bank details
• Booking info (dates, guests etc.)

But I can’t, because:
• The only “user” email is Booking Confirmed (User), which is triggered before order/payment
• After that, there’s no email event for user
• And each event only supports one email – I can’t clone Order Delivered and send it to user instead

So: How can I create a custom email for the user (not host) after order is created, with access to the full booking and vendor data?
Should I register a new event or hook into an existing one? What snippet should I use?

Also, please note:

Tokens like %order_amount%, %order_url% and other order-related values only work after the order is created and payment starts – and they are only available in emails sent to the host.

But in my setup, I use direct payment between user and host (they pay each other when they meet), and I only get a small service fee. So the user needs to know exactly how much they still owe the host, but I can’t show this in any available user email. How can I create a custom email for the user that works like the host version?

Thanks in advance!!

Hi,

If on your website hosts have to accept booking requests first (if the Booking Requests checkbox is ticked in the listing form), then the user gets the following emails:

- Booking Accepted - when the host accepted the request, this email is mainly used to ask the user to pay to finish the booking confirmation, the booking page also displays the Pay Now button
- Booking Confirmed (User) - when the booking is paid.

Both emails are available for customization in HivePress/Emails Awesome Screenshot Please note that WooCommerce also sends its own emails related to payments (for the linked order created when the booking is paid), these are also customizable in WooCommmerce settings.

Unfortunately, the Booking Confirmed (User) email doesn’t include the %order% token, and while we’ll try to add more tokens for more customizability, adding it in the current version would require code customizations for the hivepress/v1/emails/booking_confirm_user hook.

To sum up, there are 3 options to mention the remaining order amount:

  • Customize the email tokens via the hivepress/v1/emails/booking_confirm_user hook.
  • Customize WooCommerce email about the order completion, it contains the order amount and other details
  • Use the existing Booking Confirmed (User) email with the booking link and add wording like “please check Direct Payment amount in the linked booking payment details for the amount to be paid to the host”

Hope this helps

Hi HivePress team,

Thanks a lot — at this point, I’ve disabled all WooCommerce emails except for the automatic receipt to the user after they pay the service fee and commission.

Now I’m only using two final emails:
• booking_confirm_user
• booking_confirm_vendor

:white_check_mark: Everything works well, and the tokens like %order_amount% (paid), %booking_service_fee%, and general booking info display correctly.

:red_circle: But what’s still missing: I can’t display the remaining amount to be paid directly to the host, which appears with a minus sign in the order details (see screenshot).
I want to show this to both the user and the host — clearly indicating what’s left to be paid directly between them after the platform fee.

I created a custom token %booking.direct_payment%, and set the label using Loco Translate as:

“Remaining amount to be paid directly to host”

But in both confirmation emails, this token shows 0 instead of the correct value.

Can you please advise how to display this value — the direct amount owed to the host with negative -sign — inside those email templates?

————
I’d also like to show add-ons (like €20 for breakfast, €5 for extra bed) as separate lines and then display the total amount clearly (e.g. €125). I want to send this full breakdown (as negative amount) to both user and host using tokens. How can I fetch these values?

Below is the snippet I tried for %booking.direct_payment%, but it shows as 0

Here’s the code snippet I’m using — could you please check what’s missing or incorrect:?


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

	if ( $booking ) {
		$listing      = $booking->get_listing();
		$vendor       = $listing->get_vendor();
		$vendor_user  = $vendor->get_user();
		$guest_user   = $booking->get_user();

		$email_args['tokens']['listing']      = $listing;
		$email_args['tokens']['vendor']       = $vendor;
		$email_args['tokens']['vendor_user']  = $vendor_user;
		$email_args['tokens']['user']         = $guest_user;
		$email_args['tokens']['booking']      = $booking;

		$order = hivepress()->helper->get_first_array_value(
			wc_get_orders( [
				'meta_key'   => '_hp_booking',
				'meta_value' => $booking->get_id(),
			] )
		);

		if ( $order ) {
			$order_amount    = $order->get_total();
			$service_fee     = $booking->get_fee_amount();
			$direct_payment  = $order_amount - $service_fee;

			$email_args['tokens']['order_amount']          = $order_amount;
			$email_args['tokens']['booking_service_fee']   = $service_fee;
			$email_args['tokens']['booking.direct_payment'] = wp_price( $direct_payment );
		}
	}

	return $email_args;
}, 10, 1 );

Thank you very much in advance for your help!
BR

If you get the $order object, it’s a WooCommerce order one and it’s possible to fetch any details from it, but some calculations may be required. The Direct Payment is indeed defined as a negative fee, please try iterating over $order->get_fees() (I found it here in the WC_Order object docs WooCommerce Code Reference), checking the fee name, this way you can find the Direct Payment fee and use its amount but without “-”, order total is not needed in this case and the fee amount itself should be enough.

For price extras, the easiest way is probably iterating over $booking->get_price_extras() array, it contains all the price extras selected during the booking.

Hope this helps

Hej HivePress team,

I’m trying to customize the booking_confirm_user and vendor emails - to show a payment breakdown: how much has been paid (platform fee) and how much the guest still needs to pay directly to the host.

I’ve added a custom email filter and defined all required objects ($booking, $vendor, $vendor_user, $user). The related WooCommerce order is correctly retrieved, and other booking tokens display fine.

I’m now trying to fetch the negative fee line called Direct Payment from the order to calculate the remaining amount. My logic is:

foreach ( $order->get_fees() as $fee ) {
  if ( $fee->get_name() === 'Direct Payment' ) {
    $direct_payment = abs( $fee->get_total() );
    break;
  }
}

The fee appears correctly in the WooCommerce order example (–€5), but the token %booking_direct_payment% always returns 0.00 € in the email.

I’ve tried this several times (also with booking extras before), but it never worked — the token always returns 0 or nothing. Other tokens (like %booking.amount%, %vendor_user.display_name%) work fine.

:white_check_mark: What works:
• The fee is created correctly in the WooCommerce order (visible both backend and frontend);
• The fee name is exactly Direct Payment (even though it’s translated via Loco Translate);
• The order is correctly loaded in the snippet;
• Other tokens from the same snippet display properly.

:cross_mark: What doesn’t work:
• %booking_direct_payment% always returns 0 in the email.

I suspect get_fees() doesn’t return the data in this context, or the fee is not attached to the order at that point.

Could you help clarify why this is happening or suggest a better way to extract this fee into a HivePress token?

Thanks so much for your professional support!

Ewjgrass

Hi again,

Is it possible that $order->get_fees() is still empty when the email is sent, even though the order is created?

Would it help to store the fee amount as meta (e.g. using $order->update_meta_data()), and fetch it later via $order->get_meta() inside the email?

Let me know if this is a timing issue or if there’s a better way to make this work.

Thanks again for the support!

Please try to log the $order->get_fees() contents because we check fees in the Marketplace code the same way, by going through them and comparing the name.

error_log(print_r($order->get_fees(), true));

If the email is “booking_confirmed_user” and the booking is paid, the order should contain all the data at the time email is sent.

Also, if the name is translated please try comparing it to the translated text because most likely WooCommerce stores the translated fee name.

Hope this helps

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