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

时间:2014-07-22 11:14:57

标签: php wordpress email woocommerce

我想在预订时在模板中添加用户电子邮件地址吗?

我知道会在代码中添加类似的内容:

<?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' ); ?>

1 个答案:

答案 0 :(得分:0)

试试这个 - 它会从预订处提取您的姓名的电子邮件地址。

您可能想要使用printf,但这是我用来将此信息发送到Google日历的方法

$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;