简体   繁体   中英

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

I want to add the users email adress in the in the template when they make a booking?

I know it would be to add something like this to the code:

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

Here is the template code for the email - such a simple answer, but can't nail it!:

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

Try this - it pulls the email address from the booking where you are getting your name.

You may want to use printf but this is what i've used to send this info to Google Calendars

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM