I use RentalHive for a store that will offer renting of physical products.
Basically, what I want to do is send an email on the booking end date to both the host and the renter, to warn them that they have 48 hours to report any issues.
Here’s what I’ve tried so far:
add_action( 'hivepress/v1/models/booking/update_status', 'hpben_schedule_ended_action' );
add_action( 'hivepress/v1/models/booking/update_end_time', 'hpben_schedule_ended_action' );
function hpben_schedule_ended_action( $booking_id ) {
$booking = \HivePress\Models\Booking::query()->get_by_id( $booking_id );
if ( ! $booking ) {
return;
}
hivepress()->scheduler->remove_action(
'hivepress/v1/models/booking/ended',
[ $booking->get_id() ]
);
if ( $booking->get_status() === 'confirmed' ) {
hivepress()->scheduler->add_action(
'hivepress/v1/models/booking/ended',
[ $booking->get_id() ],
$booking->get_end_time()
);
}
}
add_action( 'hivepress/v1/models/booking/ended', 'hpben_send_end_notifications' );
function hpben_send_end_notifications( $booking_id ) {
$booking = \HivePress\Models\Booking::query()->get_by_id( $booking_id );
if ( ! $booking ) {
return;
}
$renter = get_user_by( 'id', $booking->get_user__id() );
$listing = \HivePress\Models\Listing::query()->get_by_id( $booking->get_listing__id() );
$host = $listing ? get_user_by( 'id', $listing->get_user__id() ) : null;
$item_name = $listing ? $listing->get_title() : 'предмета';
$site_name = get_bloginfo( 'name' );
$admin_email = get_option( 'admin_email' );
$headers = [ 'Content-Type: text/plain; charset=UTF-8' ];
if ( $host && $host->user_email ) {
$subject = sprintf( '[%s] Резервацията приключи — имате 48 часа да репортвате проблем', $site_name );
$message = sprintf(
"Hello %s,\n\n" .
"The reservation for \"%s\" has ended.\n\n" .
"You have 48 hours to report a problem if the item is returned damaged." .
"After 48 hours, the payment will be automatically released.\n\n" .
"If you have a problem, please contact us immediately at %s.\n\n" .
"Thank you,\n%s",
$host->display_name,
$item_name,
$admin_email,
$site_name
);
wp_mail( $host->user_email, $subject, $message, $headers );
}
if ( $renter && $renter->user_email ) {
$subject = sprintf( '[%s] Резервацията приключи — моля върнете предмета', $site_name );
$message = sprintf(
"Hello %s,\n\n" .
"The reservation for \"%s\" has ended.\n\n" .
"Please return the item if you haven't already." .
"Your deposit will be refunded within 48 hours if there are no issues.\n\n" .
"Thank you,\n%s",
$renter->display_name,
$item_name,
$site_name
);
wp_mail( $renter->user_email, $subject, $message, $headers );
}
}
Doesn’t seem to work though… I’d appreciate any help!