如何将用户的电子邮件地址添加到Woocommerce电子邮件模板#php


How to add the user's email address to a Woocommerce email template #php?

我想在模板中添加用户的电子邮件地址,当他们进行预订?

我知道应该在代码中添加这样的内容:

<?php if ($order->billing_email) : ?>
    <p><strong><?php _e('Email:', 'woothemes'); ?></strong> <?php echo $order->billing_email; ?></p>
<?php endif; ?>

这是电子邮件的模板代码-如此简单的答案,但不能钉它!:

<?php
/**
 * Admin new booking email
 */
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}
?>
<?php do_action( 'woocommerce_email_header', $email_heading ); ?>
<?php if ( $booking->get_order() ) : ?>
    <p><?php printf( __( 'A new booking has been made by %s. The details of this booking are as follows:', 'woocommerce-bookings' ), $booking->get_order()->billing_first_name . ' ' . $booking->get_order()->billing_last_name ); ?></p>
<?php endif; ?>
<table cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">
    <tbody>
        <tr>
            <th scope="row" style="text-align:left; border: 1px solid #eee;"><?php _e( 'Booked Product', 'woocommerce-bookings' ); ?></th>
            <td style="text-align:left; border: 1px solid #eee;"><?php echo $booking->get_product()->get_title(); ?></td>
        </tr>
        <tr>
            <th style="text-align:left; border: 1px solid #eee;" scope="row"><?php _e( 'Booking ID', 'woocommerce-bookings' ); ?></th>
            <td style="text-align:left; border: 1px solid #eee;"><?php echo $booking->get_id(); ?></td>
        </tr>
        <?php if ( $booking->has_resources() && ( $resource = $booking->get_resource() ) ) : ?>
            <tr>
                <th style="text-align:left; border: 1px solid #eee;" scope="row"><?php _e( 'Booking Type', 'woocommerce-bookings' ); ?></th>
                <td style="text-align:left; border: 1px solid #eee;"><?php echo $resource->post_title; ?></td>
            </tr>
        <?php endif; ?>
        <tr>
            <th style="text-align:left; border: 1px solid #eee;" scope="row"><?php _e( 'Booking Start Date', 'woocommerce-bookings' ); ?></th>
            <td style="text-align:left; border: 1px solid #eee;"><?php echo $booking->get_start_date(); ?></td>
        </tr>
        <tr>
            <th style="text-align:left; border: 1px solid #eee;" scope="row"><?php _e( 'Booking End Date', 'woocommerce-bookings' ); ?></th>
            <td style="text-align:left; border: 1px solid #eee;"><?php echo $booking->get_end_date(); ?></td>
        </tr>
        <?php if ( $booking->has_persons() ) : ?>
            <?php
                foreach ( $booking->get_persons() as $id => $qty ) :
                    if ( 0 === $qty ) {
                        continue;
                    }
                    $person_type = ( 0 < $id ) ? get_the_title( $id ) : __( 'Person(s)', 'woocommerce-bookings' );
            ?>
                <tr>
                    <th style="text-align:left; border: 1px solid #eee;" scope="row"><?php echo $person_type; ?></th>
                    <td style="text-align:left; border: 1px solid #eee;"><?php echo $qty; ?></td>
                </tr>
            <?php endforeach; ?>
        <?php endif; ?>
    </tbody>
</table>
<?php if ( wc_booking_order_requires_confirmation( $booking->get_order() ) ) : ?>
<p><?php _e( 'This booking has awaiting for your approval. Please check it and inform the customer if the date is available or not.', 'woocommerce-bookings' ); ?></p>
<?php endif; ?>
<?php do_action( 'woocommerce_email_footer' ); ?>

试试这个——它会从你得到名字的预订中提取电子邮件地址。

你可能想使用printf,但这是我用来发送这些信息到谷歌日历

$description .= sprintf( __( 'NAME: %s', 'woocommerce-bookings' ), $booking->get_order()->billing_first_name ) . PHP_EOL;
$description .= sprintf( __('EMAIL: %s', 'woocommerce-bookings'), $booking->get_order()->billing_email ) . PHP_EOL;
$description .= sprintf( __('PHONE: %s', 'woocommerce-bookings'), $booking->get_order()->billing_phone ) . PHP_EOL;