array( /* translators: 1: business name, 2: booking number. */ sprintf( __( '%1$s: we received your booking %2$s', 'rentbaik' ), $business, $booking['booking_number'] ), __( 'Thank you! We received your booking and will confirm it soon.', 'rentbaik' ), ), 'email_confirmed' => array( /* translators: 1: business name, 2: booking number. */ sprintf( __( '%1$s: booking %2$s confirmed', 'rentbaik' ), $business, $booking['booking_number'] ), __( 'Your booking is confirmed. See you at pick-up!', 'rentbaik' ), ), 'email_pickup' => array( /* translators: %s: business name. */ sprintf( __( '%s: reminder for your pick-up', 'rentbaik' ), $business ), __( 'This is a reminder that your rental starts soon.', 'rentbaik' ), ), 'email_return' => array( /* translators: %s: business name. */ sprintf( __( '%s: reminder to return the vehicle', 'rentbaik' ), $business ), __( 'This is a reminder that your rental ends soon. Please return the vehicle on time.', 'rentbaik' ), ), 'email_thanks' => array( /* translators: %s: business name. */ sprintf( __( 'Thank you for renting with %s', 'rentbaik' ), $business ), __( 'Thank you for renting with us. We hope to see you again!', 'rentbaik' ), ), 'cancelled' => array( /* translators: 1: business name, 2: booking number. */ sprintf( __( '%1$s: booking %2$s cancelled', 'rentbaik' ), $business, $booking['booking_number'] ), __( 'Your booking was cancelled. Contact us if you have questions.', 'rentbaik' ), ), ); if ( ! isset( $texts[ $key ] ) ) { return false; } return self::send( array( (string) $customer['email'] ), $texts[ $key ][0], $texts[ $key ][1], $booking_id ); } /** * Whether an email type is switched on. * * @param string $key Setting key. * @return bool */ private static function enabled( string $key ): bool { return (bool) Settings::get( 'notifications', $key ); } /** * Build and send an email with the booking summary. * * @param string[] $to Recipients. * @param string $subject Subject. * @param string $intro First paragraph. * @param int $booking_id Booking ID. * @param string $link Optional link for staff. * @return bool */ private static function send( array $to, string $subject, string $intro, int $booking_id, string $link = '' ): bool { $to = array_filter( $to, 'is_email' ); if ( self::$muted || empty( $to ) ) { return false; } $summary = WhatsApp::summary( $booking_id ); $body = '
'; $body .= '

' . esc_html( $intro ) . '

'; $body .= '

' . nl2br( esc_html( $summary ) ) . '

'; $payments = (array) Settings::get( 'payments', 'methods' ); $bank = (string) Settings::get( 'payments', 'bank_details' ); if ( '' === $link && ! empty( $payments ) ) { /* translators: %s: list of payment methods. */ $body .= '

' . esc_html( sprintf( __( 'Payment options: %s', 'rentbaik' ), self::payment_methods_text() ) ) . '

'; } if ( in_array( 'bank_transfer', $payments, true ) && '' !== $bank && '' === $link ) { $body .= '

' . esc_html__( 'Bank transfer details', 'rentbaik' ) . '
' . nl2br( esc_html( $bank ) ) . '

'; } $instructions = (string) Settings::get( 'payments', 'instructions' ); if ( '' !== $instructions && '' === $link ) { $body .= '

' . nl2br( esc_html( $instructions ) ) . '

'; } if ( '' !== $link ) { $body .= '

' . esc_html__( 'Open the booking', 'rentbaik' ) . '

'; } $contact = array_filter( array( (string) Settings::get( 'general', 'business_name' ), (string) Settings::get( 'general', 'business_phone' ), (string) Settings::get( 'general', 'business_email' ), ) ); $body .= '

' . esc_html( implode( ' ยท ', $contact ) ) . '

'; $headers = array( 'Content-Type: text/html; charset=UTF-8' ); $from = (string) Settings::get( 'notifications', 'from_email' ); $from_name = (string) Settings::get( 'notifications', 'from_name' ); if ( is_email( $from ) ) { $headers[] = 'From: ' . wp_specialchars_decode( str_replace( array( "\r", "\n", '"' ), '', $from_name ), ENT_QUOTES ) . ' <' . $from . '>'; } return (bool) wp_mail( $to, wp_specialchars_decode( $subject, ENT_QUOTES ), $body, $headers ); } /** * Enabled payment methods as readable text. * * @return string */ public static function payment_methods_text(): string { $labels = PaymentRepository::method_labels(); $methods = array_intersect_key( $labels, array_flip( (array) Settings::get( 'payments', 'methods' ) ) ); return implode( ', ', $methods ); } }